/** * forgot - I forgot my password and need to reset it. Takes an email address and * sends a confirmation email with a random token to that address. * * @return void **/ function forgot() { $form = new NQuickForm('reset_password', 'post'); $form->addElement('text', 'email', 'Email Address', array('maxlength' => 32, 'style' => 'width:300px;')); $form->addElement('submit', 'reset_password', 'Reset Password'); $form->addRule('email', 'You need to enter an email address.', 'required', null, 'client'); $form->addRule('email', 'The email does not appear to be the correct format', 'email', null, 'client'); if ($form->validate()) { $vals = $form->exportValues(); if (isset($vals['email'])) { $cms_auth = NModel::factory('cms_auth'); // Set the token - then send the email. if ($result = $cms_auth->setConfirmationToken($vals['email'])) { // Send the confirmation email. $user = NController::factory('users'); $user->sendConfirmationEmail($vals['email']); } } // TODO: Put this into the template and out of here. if ($result == true) { $content = '<p><b>We have sent you a confirmation - please check your email and follow the instructions.</b></p>'; } else { $content = '<p><b>There was a problem - please <a href="javascript:history.go(-1);">click back and enter your email address again.</a></b></p>'; } $this->set(array('MAIN_CONTENT' => $content, 'forgot' => 'true')); } else { $content = $form->toHTML(); $this->set(array('MAIN_CONTENT' => $content, 'forgot' => 'true')); } $this->auto_render = false; $this->render(array('layout' => 'login')); }
/** * viewlist - Shows a list of audit trail records from the current date (by default). * Can browse around records from different dates using the form * at the top of the page. * * @return void **/ function viewlist($parameter) { include_once 'n_date.php'; include_once 'n_quickform.php'; require_once 'HTML/QuickForm/Renderer/Array.php'; $this->_auth = new NAuth(); $this->auto_render = false; // set up the search form $form = new NQuickForm('audit_search', 'get'); if ($date_params = $this->getParam('date')) { $date = $this->dateStartEnd($date_params); } else { $date = $this->dateStartEnd(); } $el =& $form->addElement('date', 'date', 'Date', array('addEmptyOption' => true, 'format' => 'F d Y', 'maxYear' => 2015)); $el->setValue($date['used']); $form->addElement('submit', null, 'Search'); $renderer = new HTML_QuickForm_Renderer_Array(true, true); $form->accept($renderer); $this->set('audit_search', $renderer->toArray()); $model =& $this->getDefaultModel(); if ($model->find(array('conditions' => 'cms_created BETWEEN ' . $model->quote($date['start']) . ' AND ' . $model->quote($date['end']), 'order_by' => 'cms_created DESC'))) { $html = ''; if ($date['month']) { $html .= "<p>Showing Monthly Results for: " . date("F, Y", strtotime($date['used'])); } while ($model->fetch()) { // Actually turn the id's into something readable. $info = $this->humanizeAuditTrailRecord($model); $this->set($info); $html .= $this->render(array('action' => 'audit_trail_record', 'return' => true)); } $this->set('audit_trail', $html); $this->set('result_count', $model->numRows()); } else { $this->set('result_count', 'no'); $this->set('audit_trail', '<p>There were no results found for the specified date.</p>'); } // Exposes an RSS feed link to Admin or higher users. if (defined('RSS_AUDIT_TRAIL') && RSS_AUDIT_TRAIL) { NDebug::debug('We are checking to see if we can display the RSS feed.', N_DEBUGTYPE_INFO); $this->checkRSSFeed(); } $this->set('date', $date['used']); $this->loadSubnav($parameter); $this->render(array('layout' => 'default')); }
function viewlist() { $this->auto_render = false; include_once 'n_quickform.php'; $model =& $this->getDefaultModel(); $pk = $model->primaryKey(); $setting_forms = array(); $user_settings = $GLOBALS['USER_SETTINGS']; foreach ($user_settings as $setting => $default) { $model->reset(); $model->user_id = (int) $this->_auth->currentUserId(); $model->setting = $setting; $form = new NQuickForm('setting_' . $setting); $form->addElement('header', null, $model->settingToText($setting)); $description = $this->getSettingDescription($setting); if (!$description) { $description = 'Setting'; } $form->addElement('hidden', 'setting', $setting); $checkbox =& $form->addElement('checkbox', 'value', $description, null, array('id' => 'qf_' . $model->setting)); if ($model->find(null, true)) { // set the form action to edit $form->updateAttributes(array('action' => '/' . APP_DIR . '/' . $this->name . '/edit/' . $model->{$pk})); $form->addElement('hidden', $pk, $model->{$pk}); // check the box according to the value $checkbox->setChecked((bool) $model->value); } else { $form->updateAttributes(array('action' => '/' . APP_DIR . '/' . $this->name . '/create')); $checkbox->setChecked((bool) $default); } $form->addElement('hidden', '_referer', urlencode(NServer::env('REQUEST_URI'))); $form->addElement('submit', '__submit__', 'Submit'); $form->addRule('setting', null, 'required'); $setting_forms[] =& $form; } $this->set('settings', $setting_forms); $this->render(array('layout' => 'default')); }
function addExistingContent($parameter) { $page_model =& $this->loadModel('page'); $page_model->get($parameter); $template_container_id = isset($this->params['template_container_id']) ? $this->params['template_container_id'] : false; $asset = isset($this->params['asset']) ? $this->params['asset'] : false; // instantiate form include_once 'n_quickform.php'; $form = new NQuickForm(); $values = $form->getSubmitValues(); $form->addElement('header', null, 'Add "' . Inflector::humanize($asset) . '" content to the "' . $page_model->title . '" page'); $asset_controller =& NController::factory($asset); $asset_model =& NModel::factory($asset); $pk = $asset_model->primaryKey(); $records = array(); if ($asset_model->find()) { while ($asset_model->fetch()) { $records[$asset_model->{$pk}] = $asset_model->cms_headline; } } unset($asset_model); // add asset select $options = defined('SITE_WORKFLOW') && SITE_WORKFLOW ? array() : array('size' => 10, 'multiple' => 'multiple'); $form->addElement('select', 'asset_id', Inflector::humanize($asset), $records, $options); // hidden fields $form->addElement('hidden', 'asset', $asset); $form->addElement('hidden', 'template_container_id', $template_container_id); if (isset($this->params['_referer'])) { $form->addElement('hidden', '_referer', urlencode($this->params['_referer'])); } // finish up $form->addElement('submit', '__submit__', 'Add Content'); // rules defined('SITE_WORKFLOW') && SITE_WORKFLOW ? $form->addRule('asset_id', 'You must select a record.', 'required') : $form->addGroupRule('asset_id', 'You must select a record.', 'required'); $form->addRule('asset', '', 'required'); $form->addRule('template_container_id', '', 'required'); // check for workflow $user_rights = 0; if (SITE_WORKFLOW) { // get the users rights and bit compare them below $workflow =& NController::factory('workflow'); $user_rights = $workflow->getWorkflowUserRights($page_model); if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) { if (!($user_rights & WORKFLOW_RIGHT_EDIT)) { // they don't belong here - go to the dashboard header('Location:/' . APP_DIR . '/dashboard'); } else { if ($user_rights & WORKFLOW_RIGHT_EDIT) { $form->insertElementBefore(NQuickForm::createElement('submit', '__submit_workflow__', 'Start Workflow'), '__submit__'); $form->removeElement('__submit__'); } } } unset($workflow); } $form->addElement('header', null, 'Make it timed content?'); $timed_options = array('format' => 'Y-m-d H:i', 'minYear' => date('Y'), 'maxYear' => date('Y') + 4, 'addEmptyOption' => true); $form->addElement('date', 'timed_start', 'Timed Start', $timed_options); $form->addElement('date', 'timed_end', 'Timed End', $timed_options); if (!$user_rights) { $form->addElement('submit', '__submit_timed__', 'Add Scheduled Content'); } else { $form->addElement('submit', '__submit_workflow__', 'Start Workflow with Scheduled Content'); } if ($form->validate()) { $values = $form->exportValues(); $model =& $this->loadModel($this->name); $workflow_active = false; if (SITE_WORKFLOW) { $workflow =& NController::factory('workflow'); // check if this content is on any other page. // if it is, if either pages are part of a workflow group, we need to copy the content (go to addnewcontent with notice) // if neither do, then go ahead $asset_model =& $asset_controller->loadModel($asset_controller->name); $asset_model->get($values['asset_id']); $other_page =& $this->getContentPage($asset_controller); if ($other_page) { $owned_content = false; if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) { $owned_content = true; } else { if ($workflow_group_model =& $workflow->getWorkflowGroup($other_page)) { $owned_content = true; } } // if the content is already connected somewhere and one of the pages belongs to a workflow_group, then addNewContent with preloaded content if ($owned_content) { if (isset($values['__submit__'])) { unset($values['__submit__']); } if (isset($values['__submit_workflow__'])) { unset($values['__submit_workflow__']); } $this->redirectTo('copy_existing_content', $parameter, $values); exit; } } if (isset($values['__submit_workflow__']) && $values['__submit_workflow__']) { $workflow =& NController::factory('workflow'); if ($workflow_group_model = $workflow->getWorkflowGroup($page_model)) { $workflow_active = true; } } } $model->page_id = $parameter; if (SITE_WORKFLOW && isset($values['__submit_workflow__']) && $values['__submit_workflow__']) { $model->cms_workflow = 1; } $model->page_template_container_id = $values['template_container_id']; $model->content_asset = $values['asset']; // set the timed values $timed_start = null; $timed_end = null; include_once 'n_date.php'; if (isset($values['timed_start'])) { $timed_start = NDate::arrayToDate($values['timed_start']); $timed_start = NDate::convertTimeToUTC($timed_start); unset($values['timed_start']); } if (isset($values['timed_end'])) { $timed_end = NDate::arrayToDate($values['timed_end']); $timed_end = NDate::convertTimeToUTC($timed_end); unset($values['timed_end']); } if (!$workflow_active) { $table = $model->table(); $def = $table['timed_start']; if (NDate::validDateTime($timed_start, $def)) { $model->timed_start = $timed_start; } else { $model->timed_start = N_DAO_NOTNULL & $def ? $timed_start : 'null'; } $def = $table['timed_end']; if (NDate::validDateTime($timed_end, $def)) { $model->timed_end = $timed_end; } else { $model->timed_end = N_DAO_NOTNULL & $def ? $timed_end : 'null'; } } $model->cms_created = $model->now(); $model->cms_modified = $model->now(); $model->cms_modified_by_user = $this->_auth->currentUserID(); if (!is_array($values['asset_id'])) { $values['asset_id'] = array($values['asset_id']); } foreach ($values['asset_id'] as $asset_id) { $model->content_asset_id = $asset_id; $model->insert(); if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) { // audit trail $audit_trail =& NController::factory('audit_trail'); $audit_trail->insert(array('asset' => $asset_controller->name, 'asset_id' => $asset_id, 'action_taken' => AUDIT_ACTION_CONTENT_ADDEXISTING, 'page_content_id' => $model->{$model->primaryKey()}, 'page_id' => $model->page_id)); unset($audit_trail); } } if ($workflow_active) { $asset_controller =& NController::factory($values['asset']); $asset_controller->_auth = new NAuth(); $asset_model =& $asset_controller->getDefaultModel(); $asset_model->get($values['asset_id'][0]); $workflow_values = array(); $workflow_values['page_content_id'] = $model->{$model->primaryKey()}; $workflow_values['workflow_group_id'] = $workflow_group_model->{$workflow_group_model->primaryKey()}; // add timed content $workflow_values['timed_start'] = $timed_start; $workflow_values['timed_end'] = $timed_end; $workflow->saveWorkflow($workflow_values, WORKFLOW_ACTION_ADDEXISTING, $asset_controller); } // delete the page cache $page =& NController::singleton('page'); $page->deletePageCache($model->page_id); unset($page); // set up the referer if (isset($this->params['_referer']) && $this->params['_referer']) { $referer = urldecode($this->params['_referer']); } else { include_once 'view/helpers/url_helper.php'; $referer = urlHelper::urlFor($this, array('controller' => 'page', 'action' => 'surftoedit', 'id' => $parameter)); } header('Location:' . $referer); exit; } $this->auto_render = false; $this->page_title = 'Add Existing Content to "' . $page_model->title . '"'; $this->set(array('title' => 'Select Content', 'form' => $form->toHTML())); $this->render(array('action' => 'form', 'layout' => 'plain')); unset($page_model); }
function postGenerateForm(&$form) { $model =& $this->getDefaultModel(); $current_user_level = $this->_auth->getAuthData('user_level'); // empty the password field manually $password =& $form->getElement('password'); $password->setValue(''); // turn status on by default // $status = &$form->getElement('status'); // $status->setChecked(true); // put in confirmation password field $form->insertElementBefore(NQuickForm::createElement('password', 'confirm_password', 'Confirm Password'), 'user_level'); if ($model->{$model->primaryKey()}) { $password->setLabel('Current Password'); $form->insertElementBefore(NQuickForm::createElement('password', 'new_password', 'New Password'), 'confirm_password'); $form->addRule(array('new_password', 'confirm_password'), 'The passwords do not match', 'compare'); $form->addRule('new_password', 'The new password must be at least 8 characters long and contain upper and lower case characters and a number.', 'minlength', 8, 'client'); $form->addRule('new_password', 'The new password must be at least 8 characters long and contain upper and lower case characters and a number.', 'regex', '/[A-Z]/', 'client'); $form->addRule('new_password', 'The new password must be at least 8 characters long and contain upper and lower case characters and a number.', 'regex', '/[a-z]/', 'client'); $form->addRule('new_password', 'The new password must be at least 8 characters long and contain upper and lower case characters and a number.', 'regex', '/[0-9]/', 'client'); $password =& $form->removeElement('password'); if ($current_user_level < N_USER_ADMIN) { $form->insertElementBefore($password, 'new_password'); $password->setValue(''); $form->addFormRule(array(&$this, 'validateEdit')); $form->removeElement('user_level'); } } else { $form->addRule('password', 'That is not the correct password', 'callback', array(&$this, 'checkPassword')); $form->addRule(array('password', 'confirm_password'), 'The passwords do not match', 'compare'); } parent::postGenerateForm($form); }
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { return true; } return preg_match($regex, $elementValue['name']); } // end func _ruleCheckFileName // }}} // {{{ _ruleCheckRemove() /** * Checks if the removed element should be uploaded * * @param values All values * @access private * @return bool true if remove, array of errors otherwise */ function _ruleCheckRemove($values) { $errors = array(); if (isset($values['media_file__remove'])) { $errors['media_file'] = 'Media File is a required field'; } return empty($errors) ? true : $errors; } } NQuickForm::registerElementType('cmserror', 'n_quickform.php', 'HTML_QuickForm_cmserror'); NQuickForm::registerElementType('cmsalert', 'n_quickform.php', 'HTML_QuickForm_cmsalert'); NQuickForm::registerElementType('cms_file', 'controller/form.php', 'HTML_QuickForm_CMS_file'); NQuickForm::registerElementType('foreignkey', 'controller/form.php', 'HTML_QuickForm_foreignkey'); NQuickForm::registerElementType('fckeditor', 'controller/form.php', 'HTML_QuickForm_fckeditor'); //NQuickForm::registerElementType('CAPTCHA_Image', 'n_quickform.php', 'HTML_QuickForm_captcha'); // NQuickForm::registerElementType('nterchange_date', 'HTML/QuickForm/nterchange_date.php', 'HTML_QuickForm_nterchange_date');
function &getTreeAsSelect($name, $label) { include_once 'n_cache.php'; include_once 'n_quickform.php'; if (!($options = NCache::getTreeAsSelect())) { $options = $this->getOptions(false); if ($options) { NCache::createTreeAsSelect($options); } } return NQuickForm::createElement('select', $name, $label, $options); }
function &addElement($field, &$form, &$model) { if (!$model || !$form) { $ret = null; return $ret; } if (in_array($field, $model->form_ignore_fields)) { $ret = null; return $ret; } if (is_array($model->form_display_fields) && count($model->form_display_fields) > 0 && !in_array($field, $model->form_display_fields)) { $ret = null; return $ret; } if (is_array($model->bitmask_fields) && count($model->bitmask_fields)) { $bitmask_keys = array_keys($model->bitmask_fields); if (in_array($field, $bitmask_keys)) { $checkbox = array(); foreach ($model->bitmask_fields[$field] as $bit => $label) { $checkbox[] =& NQuickForm::createElement('checkbox', $bit, null, $label); } return $form->addElement('group', $field, ControllerForm::getFieldLabel($field, $model), $checkbox, '<br />'); } } $table = $model->table(); $def = isset($table[$field]) ? $table[$field] : false; if (!$def) { $ret = null; return $ret; } if (isset($model->form_elements[$field])) { $field_def =& $model->form_elements[$field]; if (is_object($field_def) && is_a($field_def, 'HTML_QuickForm_Element')) { return $form->addElement($field_def); } else { if (is_string($field_def)) { $field_def = array($field_def); } } if (is_array($field_def) && count($field_def) && count($field_def) < 3) { // minimum length to have field type, name and label for ($i = 1; $i < 3; $i++) { if (!isset($field_def[$i])) { if ($i == 1) { // set the field name $field_def[$i] = $field; } else { if ($field_def[0] != 'hidden' && $i == 2) { // set the field label $field_def[$i] = ControllerForm::getFieldLabel($field, $model); } } } } } $el =& call_user_func_array(array($form, 'createElement'), $field_def); if (is_object($el) && is_a($el, 'HTML_QuickForm_Element')) { $el->updateAttributes(ControllerForm::getFieldAttributes($field)); return $form->addElement($el); } $ret = null; return $ret; } if (preg_match('|^cms_|', $field) && $field != 'cms_headline') { $ret = null; return $ret; } if ($field == 'id') { return $form->addElement('hidden', 'id'); } $element_label = ControllerForm::getFieldLabel($field, $model); if ($field == 'cms_headline') { $element_label = 'Headline'; } $attributes = array(); switch (true) { case $def & N_DAO_DATE && $def & N_DAO_TIME: // $elementName = null, $elementLabel = null, $options = array(), $attributes = null $options = array('language' => 'en', 'format' => 'Y-m-d H:i', 'minYear' => 2000, 'maxYear' => date('Y') + 5); $options = ControllerForm::getFieldOptions($field, $options, $model); $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('date', $field, $element_label, $options, $attributes); $el->setLabel(array($el->_label, "{$field} date")); break; case $def & N_DAO_DATE: $options = array('language' => 'en', 'format' => 'Y-m-d', 'minYear' => 2000, 'maxYear' => date('Y') + 5); $options = ControllerForm::getFieldOptions($field, $options, $model); $attributes = array(); $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('date', $field, $element_label, $options, $attributes); $el->setLabel(array($el->_label, "{$field} date")); break; case $def & N_DAO_TIME: $options = array('language' => 'en', 'format' => 'H:i:s'); $options = ControllerForm::getFieldOptions($field, $options, $model); $attributes = array(); $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('date', $field, $element_label, $options, $attributes); $el->setLabel(array($el->_label, "{$field} date")); break; case $def & N_DAO_BOOL: $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('checkbox', $field, $element_label, null, $attributes); $el->setLabel(array($el->_label, "{$field} checkbox")); break; case $def & N_DAO_INT: $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('text', $field, $element_label, $attributes); $el->setLabel(array($el->_label, "{$field} text")); break; case $def & N_DAO_FLOAT: $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('text', $field, $element_label, $attributes); $el->setLabel(array($el->_label, "{$field} text")); break; case $def & N_DAO_TXT: $attributes = array('rows' => 15, 'cols' => 50); $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('textarea', $field, $element_label, $attributes); $el->setLabel(array($el->_label, "{$field} textarea")); break; case $def & N_DAO_BLOB: // do nothing here since binary fields shouldn't be displayed break; case $def & N_DAO_STR: $attributes = ControllerForm::getFieldAttributes($field, $attributes, $model); $el =& $form->addElement('text', $field, $element_label, $attributes); $el->setLabel(array($el->_label, "{$field} text")); break; } return $el; }
/** * Displays an Edit form for the controller's default model * * Instantiates the model, fetches the form and displays it. * Also takes care of validation prior to passing the values to update() * * @see AppController::insert(); * @param $parameter int The id of the record to be edited * @param $layout Default true. Whether to render in a layout. * @access public * @return null */ function edit($parameter, $layout = true) { $this->auto_render = false; // Track the edit - this way we can keep track of the last edits of each person. $current_user_id = isset($this->_auth) && is_object($this->_auth) ? $this->_auth->currentUserID() : 0; /*$action_track = NModel::factory('action_track'); $status = $action_track->checkAssetEditStatus($this->name, $parameter); if ($status == false) $track = $action_track->trackCurrentEdit($current_user_id, $this->name, $parameter); unset($action_track);*/ // load the model layer with info $model =& $this->getDefaultModel(); if ($model && $model->get($parameter)) { $this->convertDateTimesToClient($model); $pk = $model->primaryKey(); if (SITE_DRAFTS) { $draft_model =& $this->loadModel('cms_drafts'); $draft_model->asset = $this->name; $draft_model->asset_id = $parameter; if ($draft_model->find()) { // fill the local model with the draft info $draft_model->fetch(); $current_user_id = isset($this->_auth) && is_object($this->_auth) ? $this->_auth->currentUserID() : 0; if ($current_user_id == $draft_model->cms_modified_by_user) { $content = unserialize($draft_model->draft); foreach ($content as $field => $val) { $model->{$field} = $val; } $this->flash->set('notice', 'You are currently editing your draft of this record.'); $this->flash->now('notice'); } else { $user_model =& $this->loadModel('cms_auth'); $user_model->get($draft_model->cms_modified_by_user); $this->flash->set('notice', 'This record has been saved as a draft by "' . $user_model->real_name . '".'); $this->flash->now('notice'); unset($user_model); } } } // create the form $cform = new ControllerForm($this, $model); $form =& $cform->getForm(); // is a page_content_id passed? $page_content_id = $this->getParam('page_content_id') ? (int) $this->getParam('page_content_id') : false; if ($page_content_id) { $page_content =& NController::factory('page_content'); $page_content_model =& $page_content->getDefaultModel(); $page_content_model->get($page_content_id); $page_content->convertDateTimesToClient($page_content_model); $page_model = $page_content_model->getLink('page_id', 'page'); } // check if this content belongs to a different workflow group or is currently in process $owned_content = false; if (SITE_WORKFLOW) { $workflow =& NController::factory('workflow'); $workflow_group_model = false; $workflow_model = false; $user_rights = 0; if ($page_content_id) { $workflow_model =& $workflow->getDefaultModel(); $workflow_model->page_content_id = $page_content_id; $workflow_model->asset = $this->name; $workflow_model->asset_id = $model->{$pk}; $workflow_model->completed = 0; if ($workflow_model->find(null, true)) { $owned_content = true; } $workflow_group_model =& $workflow->getWorkflowGroup($page_model); $user_rights = $workflow->getWorkflowUserRights($page_model); } else { if ($workflow_group_model =& $workflow->findContentWorkflowGroup($this)) { if ($workflow_model =& $workflow->findContentWorkflow($workflow_group_model->{$workflow_group_model->primaryKey()}, $this)) { $page_model =& $this->loadModel('page'); if ($page_model->get($workflow_model->page_id)) { $owned_content = true; } $user_rights = $workflow->getWorkflowUserRights($page_model); } else { $page_content =& NController::factory('page_content'); $page_model = $page_content->getContentPage($this); if ($page_model) { $owned_content = true; } $user_rights = $workflow->getWorkflowUserRights($page_model); } } } if (!$owned_content || $owned_content && $user_rights & WORKFLOW_RIGHT_EDIT) { if ($workflow_model && $workflow_model->{$workflow_model->primaryKey()}) { $form->removeElement('__submit_draft__'); $form->insertElementBefore(NQuickForm::createElement('submit', '__submit_workflow__', 'Start Workflow'), '__submit__'); $form->removeElement('__submit__'); $workflow_draft = unserialize($workflow_model->draft); $form->setDefaults($workflow_draft); } else { if ($user_rights & WORKFLOW_RIGHT_EDIT) { $form->insertElementBefore(NQuickForm::createElement('submit', '__submit_workflow__', 'Start Workflow'), '__submit__'); $form->removeElement('__submit__'); } } } else { if ($owned_content) { $this->flash->set('notice', 'The record you are attempting to edit belongs to the "' . $workflow_group_model->workflow_title . '" Workflow Group'); $this->flash->now('notice'); $this->set('MAIN_CONTENT', '<p>Please go to the dashboard to continue.</p>'); $this->render(array('layout' => 'default')); exit; } } } // if page_content_id or (it's workflow owned and this user has editing rights) if ($page_content_id || $owned_content && $user_rights & WORKFLOW_RIGHT_EDIT) { // add timed content if ($owned_content && $user_rights & WORKFLOW_RIGHT_EDIT && $workflow_model) { $form->setDefaults(array('timed_start' => $workflow_model->timed_start, 'timed_end' => $workflow_model->timed_end)); } else { if ($page_content_id) { $form->setDefaults(array('timed_start' => $page_content_model->timed_start, 'timed_end' => $page_content_model->timed_end)); } } $page_content_model =& NModel::factory('page_content'); $timed_start_el =& ControllerForm::addElement('timed_start', $form, $page_content_model); $timed_end_el =& ControllerForm::addElement('timed_end', $form, $page_content_model); if ($timed_start_el) { $form->insertElementBefore($form->removeElement('timed_start'), $form->elementExists('__submit_workflow__') ? '__submit_workflow__' : '__submit__'); } if ($timed_end_el) { $form->insertElementBefore($form->removeElement('timed_end'), $form->elementExists('__submit_workflow__') ? '__submit_workflow__' : '__submit__'); } } // assign the info and render $this->base_dir = APP_DIR; $assigns = array(); $fields = $model->fields(); if ($form->validate() && $this->update(true)) { // If it validates and updates, then clear out the action track. /*$action_track = NModel::factory('action_track'); $action_track->completeCurrentEdit($current_user_id, $this->name, $parameter); unset($action_track);*/ $this->flash->set('notice', 'Your record has been saved.'); $this->redirectTo('show', $parameter); } else { if ($model) { $this->set($model->toArray()); $this->set(array('form' => $form->toHTML(), 'asset' => $this->name, 'asset_name' => $this->page_title ? $this->page_title : Inflector::humanize($this->name))); } } } else { $this->flash->set('notice', 'The specified record could not be found.'); $this->flash->now('notice'); } if ($this->getParam('layout') == 'false') { $layout = false; } $this->render($layout ? array('layout' => 'default') : null); }