grigory51

Action

May 28th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2.  
  3. class PluginMaterial_ActionMaterial extends ActionPlugin {
  4.  
  5. public function Init() {
  6. $this->SetDefaultEvent('admin');
  7. }
  8.  
  9. protected function RegisterEvent() {
  10. $this->AddEvent('admin', 'EventAdmin');
  11. $this->AddEvent('add', 'EventAddMaterial');
  12. }
  13.  
  14. protected function EventAdmin() {
  15.  
  16. $this->oUserCurrent = $this->User_GetUserCurrent();
  17. if (!$this->oUserCurrent or !$this->oUserCurrent->isAdministrator()) {
  18. return $this->EventNotFound();
  19. }
  20.  
  21. $aMaterials = $this->PluginMaterial_ModuleMaterial_GetAll();
  22. $this->Viewer_AppendStyle(Plugin::GetTemplatePath(__CLASS__) . 'css/list.css');
  23. $this->Viewer_AppendStyle(Plugin::GetTemplatePath(__CLASS__) . 'css/preview.css');
  24. $this->Viewer_AppendScript(Plugin::GetTemplatePath(__CLASS__) . 'js/list.js');
  25. $this->Viewer_Assign('aMaterials', $aMaterials);
  26. }
  27.  
  28. protected function EventAddMaterial() {
  29. if (isAjaxRequest()) {
  30. if (!empty($_POST)) {
  31. $this->Security_ValidateSendForm();
  32. $sLink = getRequestStr('link', null, 'post');
  33. // $bCommit = (bool) getRequest('commit', null, 'post');
  34.  
  35. $oCombiner = new PluginMaterial_ModuleLinkCombiner($sLink);
  36. if (!is_null($oCombiner->getEntity())) {
  37. $this->Viewer_SetResponseAjax('json');
  38. $this->Viewer_AssignAjax('previewJSON', $oCombiner->getPreviewJSON());
  39. $iId = $this->PluginMaterial_ModuleMaterial_AddWithOutCommit($oCombiner->getEntity());
  40. $this->Viewer_AssignAjax('materialId', $iId);
  41. } else {
  42. $this->Viewer_SetResponseAjax('json');
  43. $this->Message_AddError($this->Lang_Get('plugin.material.link_error'));
  44. }
  45. return;
  46. }
  47. }
  48. return $this->EventNotFound();
  49. }
  50.  
  51. }
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment