CheckAccess()) { return $this->DisplayErrorPage(); } /* Module Edition */ if (isset($params['cancel'])) { $this->Redirect($id, 'defaultadmin', $returnid); exit; } if (isset($params['module_id']) && !empty($params['module_id'])) { $module = MCFModule::retrieveByPk($params['module_id']); } else { $module = new MCFModule(); $module->setParentModule(0); $module->setModuleFriendlyname('Module'); } // Tabs $tabs = new MCFAdminTabs($this, $params); $tabs->addTabs(array( // 'main' => $this->Lang('main'), 'fields' => $this->Lang('fields'), 'filters' => $this->Lang('filters'), 'actions' => $this->Lang('actions'), 'logic' => $this->Lang('logic'), 'features' => $this->Lang('extra_features'), 'options' => $this->Lang('options'), )); // Logic if (isset($params['move_up']) && is_array($params['move_up'])) { foreach ($params['move_up'] as $key => $value) { $module->orderExtraFields($key, 'up'); $module->save(); } } if (isset($params['move_down']) && is_array($params['move_down'])) { foreach ($params['move_down'] as $key => $value) { $module->orderExtraFields($key, 'down'); $module->save(); } } if (isset($params['publish']) || isset($params['save'])) { $module->populateFromArray($params); if (!isset($params['show_module'])) { //var_dump($params); $module->setShowModule(0); } if (!isset($params['api_enabled'])) { //var_dump($params); $module->setAPIEnabled(0); } if (!isset($params['is_user_module'])) { //var_dump($params); $module->setIsUserModule(0); } if (!isset($params['is_protected'])) { //var_dump($params); $module->setIsProtected(0); } // REORDER FIELDS if (isset($params['fields_ordered'])) { $str = $module->getStructure(); foreach ($params['fields_ordered'] as $tab_key => $tabs) { foreach ($tabs as $fieldset_key => $fields_ordered) { if ($fields_ordered != '') { $str->reorderFields($tab_key, $fieldset_key, $fields_ordered); } } } $module->setStructure($str); } $module->save(); if (isset($params['publish'])) { $generator = new MCFGenerator($module); try{ $generator->publish(); $this->SetFlashMessage('Module ' . $module->getModuleName() . ' published!'); echo '
'; // var_dump($module->getStructure()); // echo ''; // --- TAB FORM --- $tab_form = new CMSForm('MCFactory', $id, 'manage_tabs', $returnid); $tab_form->setButtons(array()); $tab_form->setWidget('module_id', 'hidden', array('value' => $module->getId())); $tab_form->setWidget('name', 'text', array('size' => 45)); $this->smarty->assign('tab_form', $tab_form); // --- TAB REMOVE FORM --- $tab_remove_form = new CMSForm('MCFactory', $id, 'manage_tabs', $returnid); $tab_remove_form->setButtons(array()); $tab_remove_form->setWidget('module_id', 'hidden', array('value' => $module->getId())); $tab_remove_form->setWidget('remove_tab', 'hidden'); $this->smarty->assign('tab_remove_form', $tab_remove_form); // --- FIELDSET FORM --- $fieldset_form = new CMSForm('MCFactory', $id, 'manage_fieldset', $returnid); $fieldset_form->setButtons(array()); $fieldset_form->setWidget('module_id', 'hidden', array('value' => $module->getId())); $fieldset_form->setWidget('tab_key', 'hidden'); $fieldset_form->setWidget('name', 'text', array('size' => 45)); $this->smarty->assign('fieldset_form', $fieldset_form); // --- REMOVE FIELDSET FORM --- $remove_fieldset_form = new CMSForm('MCFactory', $id, 'manage_fieldset', $returnid); $remove_fieldset_form->setButtons(array()); $remove_fieldset_form->setWidget('module_id', 'hidden', array('value' => $module->getId())); $remove_fieldset_form->setWidget('tab_key', 'hidden'); $remove_fieldset_form->setWidget('remove_fieldset', 'hidden'); $this->smarty->assign('remove_fieldset_form', $remove_fieldset_form); // --- ADD/EDIT FIELD FORM --- $add_field_form = new CMSForm('MCFactory', $id, 'manage_field', $returnid); $add_field_form->setButtons(array()); $add_field_form->setWidget('module_id', 'hidden', array('value' => $module->getId())); $add_field_form->setWidget('tab_key', 'hidden'); $add_field_form->setWidget('fieldset_key', 'hidden'); $add_field_form->setWidget('label', 'text', array('size' => 45)); $add_field_form->setWidget('name', 'hidden'); $add_field_form->setWidget('place', 'select', array('values' => $module->getStructure()->getFieldsetsWithTabsForSelect())); $add_field_form->setWidget('type', 'hidden'); $add_field_form->setWidget('type_select', 'select', array('values' => $select)); $add_field_form->setWidget('options', 'textarea', array('cols' => 40, 'rows' => 4, 'addtext' => 'style="width:25em;height:10em;"')); $add_field_form->setWidget('column', 'checkbox'); $add_field_form->setWidget('filter', 'checkbox'); $add_field_form->setWidget('frontend', 'checkbox'); $this->smarty->assign('add_field_form', $add_field_form); // --- REMOVE FIELD FORM --- $remove_field_form = new CMSForm('MCFactory', $id, 'manage_field', $returnid); $remove_field_form->setButtons(array()); $remove_field_form->setWidget('module_id', 'hidden', array('value' => $module->getId())); $remove_field_form->setWidget('tab_key', 'hidden'); $remove_field_form->setWidget('fieldset_key', 'hidden'); $remove_field_form->setWidget('field', 'hidden'); $this->smarty->assign('remove_field_form', $remove_field_form); // Actions $this->smarty->assign('add_action_url', (isset($params['module_id'])) ? $this->CreateLink($id, 'manage_action', $returnid, '', array('module_id' => $params['module_id']), '', true, false) : 'First save the module core in order to add actions'); $actions = (isset($params['module_id'])) ? MCFModuleAction::doSelect(array('where' => array('module_id' => $params['module_id']))) : array(); foreach ($actions as $action) { $action->edit_button = $this->CreateLink($id, 'manage_action', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/edit.gif', $this->Lang('edit'), '', '', 'systemicon'), array('module_action_id' => $action->getId())); $action->edit_url = $this->CreateLink($id, 'manage_action', $returnid, '', array('module_action_id' => $action->getId()), '', true); $action->delete_url = $this->CreateLink($id, 'delete_action', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/delete.gif', $this->Lang('delete'), '', '', 'systemicon'), array('module_action_id' => $action->getId())); if ($action->is_public == 1) { $action->is_public_icon = cmsms()->get_variable('admintheme')->DisplayImage('icons/system/true.gif', '', '', '', 'systemicon'); } else { $action->is_public_icon = cmsms()->get_variable('admintheme')->DisplayImage('icons/system/false.gif', '', '', '', 'systemicon'); } } $this->smarty->assign('actions', $actions); // Extra features $extra_features = $module->getExtraFeatures(); $smarty_events = array(); if (isset($params['module_id'])) { if (is_array($extra_features->getEvents())) { foreach ($extra_features->getEvents() as $module_name => $events) { foreach ($events as $event_name => $code) { $smarty_events[] = array( 'module_name' => $module_name, 'event_name' => $event_name, 'edit' => $this->CreateLink($id, 'manage_event', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/edit.gif', $this->Lang('edit'), '', '', 'systemicon'), array('module_id' => $params['module_id'], 'module_name' => $module_name, 'event_name' => $event_name)), 'delete' => $this->CreateLink($id, 'manage_event', $returnid, cmsms()->get_variable('admintheme')->DisplayImage('icons/system/delete.gif', $this->Lang('edit'), '', '', 'systemicon'), array('module_id' => $params['module_id'], 'delete' => true, 'module_name' => $module_name, 'event_name' => $event_name), 'Are you sure you want to delete this event?') ); } } } } $this->smarty->assign('events', $smarty_events); $this->smarty->assign('add_event', (isset($params['module_id'])) ? $this->CreateLink($id, 'manage_event', $returnid, '', array('module_id' => $params['module_id']), '', true, false) : 'First save the module core in order to add events'); // Templates: Restore $this->smarty->assign('templates_restore_url', (isset($params['module_id'])) ? $this->CreateLink($id, 'templates_restore', $returnid, '', array('module_id' => $params['module_id']), '', true, false) : 'First save the module core in order to manage templates'); //var_dump($_SERVER); $smarty->assign('request_uri', $_SERVER['REQUEST_URI']); // $tabs->setTabContent('fields', $this->ProcessTemplate('admin.edit_fields.tpl')); $smarty->assign('fields_modal', $this->ProcessTemplate('admin.edit_fields_modal.tpl')); $tabs->setTabContent('filters', $this->ProcessTemplate('admin.edit_filters.tpl')); $tabs->setTabContent('actions', $this->ProcessTemplate('admin.edit_actions.tpl')); $tabs->setTabContent('features', $this->ProcessTemplate('admin.edit_features.tpl')); $tabs->setTabContent('logic', $this->ProcessTemplate('admin.edit_logic.tpl')); $tabs->setTabContent('options', $this->ProcessTemplate('admin.edit_options.tpl')); $smarty->assign('module', $module); $smarty->assign('tabs', $tabs); echo $this->ProcessTemplate('edit.tpl');