/tags/2_1/TimeIt/modules/TimeIt/classes/FormHandler/Calendar.php

https://github.com/planetenkiller/TimeIt-zk-12 · PHP · 182 lines · 143 code · 22 blank · 17 comment · 31 complexity · 5c2d8c3ef6b9d0ec59b789cbac632066 MD5 · raw file

  1. <?php
  2. /**
  3. * TimeIt Calendar Module
  4. *
  5. * @copyright (c) TimeIt Development Team
  6. * @link http://code.zikula.org/timeit
  7. * @version $Id$
  8. * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9. * @package TimeIt
  10. * @subpackage FormHandler
  11. */
  12. /**
  13. * Form handler for calendar creation and modification.
  14. */
  15. class TimeIt_FormHandler_calendar
  16. {
  17. var $mode;
  18. var $cid;
  19. function initialize(&$render)
  20. {
  21. $func = FormUtil::getPassedValue('func', null, 'GET');
  22. if($func == 'calendarsModify')
  23. {
  24. $id = FormUtil::getPassedValue('id', false, 'GET');
  25. if(!$id)
  26. {
  27. return LogUtil::registerError(_TIMEIT_NOIDPATAM, 404);
  28. }
  29. $this->mode = 'edit';
  30. $this->cid = $id;
  31. $obj = pnModAPIFunc('TimeIt','calendar','get', $id);
  32. if(empty($obj))
  33. {
  34. return LogUtil::registerError(_TIMEIT_IDNOTEXIST, 404);
  35. }
  36. $render->assign($obj);
  37. } else
  38. {
  39. $this->mode = 'add';
  40. }
  41. $render->assign('mode', $this->mode);
  42. // ContactList integration
  43. if (pnModAvailable('ContactList'))
  44. {
  45. $render->assign('ContactListModuleOK', true);
  46. } else
  47. {
  48. $render->assign('ContactListModuleOK', false);
  49. }
  50. $config = array();
  51. $config['workflowItems'] = array(array('text'=>'standard','value'=>'standard'),
  52. array('text'=>'moderate','value'=>'moderate'));
  53. $config['defaultViewItems'] = array(array('text'=>_MONTH,'value'=>'month'),
  54. array('text'=>_WEEK,'value'=>'week'),
  55. array('text'=>_DAY,'value'=>'day'));
  56. $config['defaultTemplateItems'] = array(array('text'=>'default','value'=>'default'),
  57. array('text'=>'list','value'=>'list'));
  58. // ContactList integration
  59. if (pnModAvailable('ContactList'))
  60. {
  61. $render->assign('ContactListModuleOK', true);
  62. } else
  63. {
  64. $render->assign('ContactListModuleOK', false);
  65. }
  66. // check all event plugins
  67. $eventplugins = TimeIt::getEventPlugins(true);
  68. $availablePlugins = array();
  69. $availablePluginsIndex = array();
  70. foreach($eventplugins AS $type => $plugins) {
  71. foreach($plugins AS $plugin) {
  72. $classname = TimeIt::getEventPluginClassname($plugin);
  73. $dependencyCheckOk = false;
  74. if(is_callable(array($classname, 'dependencyCheck'))) {
  75. if(call_user_func(array($classname, 'dependencyCheck'))) {
  76. $dependencyCheckOk = true;
  77. }
  78. } else {
  79. $dependencyCheckOk = true;
  80. }
  81. if($dependencyCheckOk) {
  82. if(!isset($availablePlugins[$type])) {
  83. $availablePlugins[$type] = array();
  84. }
  85. $availablePluginsIndex[] = $plugin;
  86. $availablePlugins[$type][] = array('value'=>TimeIt::getEventPluginNameWithoutType($plugin),
  87. 'text'=>TimeIt::getEventPluginInstance($plugin)->getDisplayname());
  88. }
  89. }
  90. }
  91. // assign variables
  92. $locationEventPlugins = array(array('text'=>'TimeIt','value'=>'TimeIt'));
  93. if (in_array('LocationLocations', $availablePluginsIndex)) {
  94. $render->assign('locationsModuleOK', true);
  95. } else {
  96. $render->assign('locationsModuleOK', false);
  97. }
  98. if (in_array('ContactFormicula', $availablePluginsIndex)){
  99. $render->assign('formiculaModuleOk', true);
  100. $render->assign('formiculaModuleOkReadOnly', false);
  101. } else{
  102. $render->assign('formiculaModuleOk', false);
  103. $render->assign('formiculaModuleOkReadOnly', true);
  104. }
  105. if (in_array('ContactAddressbook', $availablePluginsIndex)){
  106. $render->assign('AddressbookModuleOK', true);
  107. } else{
  108. $render->assign('AddressbookModuleOK', false);
  109. }
  110. $config['eventPluginsLocationItems'] = $availablePlugins['location'];
  111. $config['eventPluginsContactItems'] = $availablePlugins['contact'];
  112. $render->append('config', $config, true);
  113. }
  114. function handleCommand(&$render, &$args)
  115. {
  116. if ($args['commandName'] == 'create')
  117. {
  118. if (!$render->pnFormIsValid())
  119. {
  120. return false;
  121. } else
  122. {
  123. $data = $render->pnFormGetValues();
  124. if($data['privateCalendar'] == false && $data['globalCalendar'] == false && $data['friendCalendar'] == false)
  125. {
  126. return LogUtil::registerError(_TIMEIT_ERROR_2);
  127. }
  128. if($data['config']['subscribeMode'] == 'formicula' && empty($data['config']['formiculaFormId']))
  129. {
  130. $form = &$render->pnFormGetPluginById('formiculaFormId');
  131. $form->setError(_PNFORM_MANDATORYERROR);
  132. return false;
  133. }
  134. if($this->mode == 'edit')
  135. {
  136. $data['id'] = $this->cid;
  137. $ret = pnModAPIFunc('TimeIt','calendar','update',$data);
  138. if($ret)
  139. {
  140. LogUtil::registerStatus (_UPDATESUCCEDED);
  141. } else
  142. {
  143. LogUtil::registerError(_UPDATEFAILED);
  144. }
  145. } else
  146. {
  147. $ret = pnModAPIFunc('TimeIt','calendar','create',$data);
  148. if($ret)
  149. {
  150. LogUtil::registerStatus (_CREATESUCCEDED);
  151. } else
  152. {
  153. LogUtil::registerError(_CREATEFAILED);
  154. }
  155. }
  156. }
  157. }
  158. $render->pnFormRedirect(pnModURL('TimeIt', 'admin', 'calendars'));
  159. }
  160. }