示例#1
0
 function removeJavascript($id = 0)
 {
     $page =& NController::singleton('page');
     $page->base_view_dir = ROOT_DIR;
     $page->view_caching = (bool) PAGE_CACHING;
     $page->view_cache_lifetime = JS_CACHE_LIFETIME;
     $view_options = array('action' => 'blank');
     // REMOVE JAVASCRIPT CACHES
     $javascript_caches = array('javascript', 'javascript_secure', 'javascript_qualified', 'admin_javascript', 'admin_edit_javascript');
     foreach ($javascript_caches as $javascript_cache) {
         $page->view_cache_name = $javascript_cache;
         $view =& NView::singleton($page);
         $title = ucfirst(str_replace('_', ' ', $javascript_cache));
         if ($view->isCached($view_options)) {
             $cache_cleared = $view->clearCache($view_options);
             if ($cache_cleared) {
                 NDebug::debug($title . ' cache removed due to page edit on Page ID ' . $id . '.', N_DEBUGTYPE_CACHE);
             } else {
                 NDebug::debug($title . ' cache failed attempted removal due to page edit on Page ID ' . $id . '.', N_DEBUGTYPE_CACHE);
             }
         } else {
             NDebug::debug($title . ' cache failed attempted removal due to page edit on Page ID ' . $id . ' but cache does not exist.', N_DEBUGTYPE_CACHE);
         }
     }
     unset($view);
 }
示例#2
0
 function test_controller_exists()
 {
     $c_exists =& NController::exists('page');
     $this->assertTrue($c_exists, 'Page Controller exists()');
     $c =& NController::singleton('page');
     $this->assertInstanceOf('PageController', $c);
     $c2 =& NController::singleton('page');
     $this->assertSame($c, $c2, "NController::singleton() returns a reference to the same object");
     unset($c2);
     $class_name = $c->getClassName('page');
     $this->assertEquals($class_name, "PageController", "getClassName returns proper name");
 }
 function viewlist($parameter = null, $layout = true, $model = false)
 {
     $options = array();
     $assigns = array();
     $model = $model ? $model : $this->getDefaultModel();
     $this->page_title = Inflector::humanize($this->name);
     $this->auto_render = false;
     $this->base_dir = APP_DIR;
     $assigns['TITLE'] = Inflector::humanize($this->name);
     if ($model) {
         $this->get_search_field($model, $options);
         $this->get_viewlist_options($model, $options);
         $this->get_sort_options($model, $options);
         $this->set_pagination($model);
         $model->find($options);
         $page_content =& NController::singleton('page_content');
         $page_content_model =& $page_content->getDefaultModel();
         $pk = $model->primaryKey();
         $models = array();
         $headline = $model->getHeadline() ? $model->getHeadline() : 'cms_headline';
         $i = 0;
         while ($model->fetch()) {
             $arr = $model->toArray();
             $arr['_headline'] = isset($arr['cms_headline']) && $arr['cms_headline'] ? $arr['cms_headline'] : $model->makeHeadline();
             $arr['_remove_delete'] = $page_content_model->isWorkflowContent($this->name, $arr[$pk]) ? 1 : 0;
             // Remove delete for models that have specified this.
             $arr['_remove_delete'] = isset($model->remove_delete) && $model->remove_delete == true ? 1 : 0;
             $models[] = $arr;
             unset($arr);
         }
         // Override standard paging limit if chosen in the model file.
         $paging = isset($model->paging) ? $model->paging : $this->paging;
         // If paging is not disabled in the model AND the records are > than the paging size AND not searching.
         if ($paging > 0 && count($models) > $paging && !$options['is_search']) {
             SmartyPaginate::connect($this->name);
             SmartyPaginate::setLimit($paging, $this->name);
             SmartyPaginate::setTotal(count($models), $this->name);
             $view =& NView::singleton($this);
             SmartyPaginate::assign($view, 'paginate', $this->name);
             // TODO: Could be more efficient and only get records it needs to.
             $models = array_slice($models, SmartyPaginate::getCurrentIndex($this->name), SmartyPaginate::getLimit($this->name));
             $this->set('paging', true);
         }
         $this->set(array('rows' => $models, 'asset' => $this->name, 'asset_name' => $this->page_title));
         unset($models);
     }
     $this->render(array('layout' => 'default'));
 }
示例#4
0
 /**
  * checkChildOfItself - A page cannot be a child of itself. That would be
  * illogical and cause that page to disappear. Returns true if OK and false
  * if you're setting something to be a child of itself.
  *
  * @param	int		The page_id of a page.
  * @return 	boolean
  **/
 function checkChildOfItself($parent_id)
 {
     $parent_id = (int) $parent_id;
     $pk = $this->primaryKey();
     $page =& NController::singleton('page');
     $page_id = (int) $page->getParam($pk);
     if (!$page_id) {
         return true;
     }
     if ($page_id == $parent_id) {
         return false;
     }
     $all_children = $this->getAllChildren($page_id, false, false);
     foreach ($all_children as $child) {
         if ($parent_id == $child[$pk]) {
             return false;
         }
     }
     return true;
 }
 function reorder()
 {
     $id = isset($this->params['id']) ? (int) $this->params['id'] : false;
     if (!$id) {
         return;
     }
     $before = isset($this->params['before']) ? (int) $this->params['before'] : false;
     if (($model =& $this->getDefaultModel()) && $model->get($id)) {
         $pk = $model->primaryKey();
         $page_content_model =& NModel::factory($this->name);
         $page_content_model->page_id = $model->page_id;
         $page_contents = array();
         if ($page_content_model->find()) {
             $before_found = false;
             $item = null;
             while ($page_content_model->fetch()) {
                 if ($page_content_model->{$pk} == $id) {
                     // pull the "id" record out of the array
                     $item = clone $page_content_model;
                 } else {
                     $page_contents[] = clone $page_content_model;
                 }
             }
             if (!$before) {
                 // if there is no before, then the item goes last
                 $page_contents[] = $item;
             } else {
                 // loop through until you find "before" and then splice the "id" in front of it
                 foreach ($page_contents as $key => $page_content) {
                     if ($page_content->{$pk} == $before) {
                         array_splice($page_contents, $key, 1, array($item, $page_content));
                         break;
                     }
                 }
             }
             $i = 0;
             foreach ($page_contents as $key => $page_content) {
                 $page_content->content_order = $i;
                 $page_content->save(false, false);
                 // second false prevents converting time to UTC (unnecessary for a reorder)
                 $i++;
             }
         }
         $page =& NController::singleton('page');
         $page->deletePageCache($model->page_id);
         unset($page);
         unset($page_contents);
         unset($page_content_model);
         unset($model);
     }
 }
 function submit($workflow_id)
 {
     if (false !== strpos($workflow_id, ';')) {
         $workflow_id = explode(';', $workflow_id);
     } else {
         $workflow_id = array($workflow_id);
     }
     $this->auto_render = false;
     $model =& $this->getDefaultModel();
     $pk = $model->primaryKey();
     // get the workflow info
     $workflows = array();
     foreach ($workflow_id as $id) {
         $model->reset();
         $model->submitted = 0;
         if ($model->get($id)) {
             $this->convertDateTimesToClient($model);
             $workflows[] = clone $model;
         }
     }
     if (empty($workflows)) {
         $this->redirectTo('index');
     }
     $html = '';
     foreach ($workflows as $model) {
         // push the times back so they can get pushed forward again on update()
         // get the asset info for the email
         $asset_ctrl =& NController::factory($model->asset);
         $asset_model =& NModel::factory($model->asset);
         if (!$asset_ctrl || !$asset_model->get($model->asset_id)) {
             $this->redirectTo('index');
         }
         $asset_name = $asset_ctrl->page_title ? $asset_ctrl->page_title : Inflector::humanize($asset_ctrl->name);
         // get the page info for the email
         $page_content_model = $workflows[0]->getLink('page_content_id', 'page_content');
         $page =& NController::singleton('page');
         $page_model =& $page->getDefaultModel();
         $page_model->reset();
         if (!$page_model->get($page_content_model->page_id)) {
             $this->redirectTo('index');
         }
         $live_url = preg_replace('/\\/$/', '', PUBLIC_SITE) . $page->getHref($page_model->toArray());
         $page->nterchange = true;
         $preview_url = preg_replace('/\\/$/', '', defined('ADMIN_URL') && ADMIN_URL ? ADMIN_URL : PUBLIC_SITE) . $page->getHref($page_model->toArray());
         $dashboard_url = preg_replace('/\\/$/', '', defined('ADMIN_URL') && ADMIN_URL ? ADMIN_URL : PUBLIC_SITE) . '/' . APP_DIR . '/dashboard';
         $auth = new NAuth();
         $user_model =& NModel::factory('cms_auth');
         $user_model->get($auth->currentUserId());
         unset($auth);
         $workflow_group =& $workflows[0]->getLink('workflow_group_id', 'workflow_group');
         // get the users
         $user_rights = $this->getWorkflowUserRights($page_model, $user_model->{$user_model->primaryKey()});
         $users = $this->getNotifyUsers($model->{$pk}, $user_rights);
         /*
         varDump('###################');
         varDump($user_rights);
         foreach ($users as $user) {
         	varDump($user->toArray());
         }
         exit;
         */
         include_once 'Mail.php';
         $mail =& Mail::factory('mail', "-f{$user_model->email}");
         $headers['From'] = "{$user_model->real_name} <{$user_model->email}>";
         $headers['Subject'] = 'Website: "' . $workflow_group->workflow_title . '" Workflow Group has content waiting for your approval';
         // $headers['To'] = '';
         $msg = '';
         $msg .= "The workflow for the \"{$asset_model->cms_headline}\" {$asset_name} record on the {$page_model->title} page is awaiting your approval.\n\n";
         if ($model->comments) {
             $msg .= "COMMENTS:\n{$model->comments}\n\n";
         }
         $msg .= "You can view the current live page at:\n{$live_url}\n\n";
         $msg .= "You can preview the page at:\n{$preview_url}\n\n";
         $msg .= "To Approve/Decline the changes, please go to Your Dashboard:\n" . $dashboard_url;
         // gather the users
         $user_array = array();
         $recipients = array();
         foreach ($users as $user) {
             if ($user->{$user->primaryKey()} == $user_model->{$user_model->primaryKey()}) {
                 continue;
             }
             $email = "{$user->real_name} <{$user->email}>";
             $recipients[] = $email;
             // $headers['To'] .= ($headers['To']?', ':'') . $email;
             $user_array[] = $user->toArray();
         }
         if (!empty($recipients)) {
             $mail->send($recipients, $headers, $msg);
         }
         unset($mail);
         // update the workflow and set submitted to true
         $model->submitted = 1;
         include_once 'n_date.php';
         $model->cms_created = NDate::convertTimeToUTC($model->cms_created, '%Y-%m-%d %H:%M:%S');
         $model->cms_modified = NDate::convertTimeToUTC($model->cms_modified, '%Y-%m-%d %H:%M:%S');
         $model->update();
         if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) {
             // audit trail
             $audit_trail =& NController::factory('audit_trail');
             $audit_trail->insert(array('asset' => $model->asset, 'asset_id' => $model->asset_id, 'action_taken' => AUDIT_ACTION_WORKFLOW_SUBMIT, 'workflow_id' => $model->{$model->primaryKey()}, 'workflow_group_id' => $model->workflow_group_id, 'page_id' => $model->page_id, 'page_content_id' => $model->page_content_id));
             unset($audit_trail);
         }
         // set up the view
         $this->set('asset_name', $asset_name);
         $this->set('asset', $asset_model->toArray());
         $this->set('workflow_group', $workflow_group->toArray());
         $this->set('page', $page_model->toArray());
         $this->set('users', $user_array);
         $html .= $this->render(array('action' => 'send', 'return' => true));
     }
     $this->set('MAIN_CONTENT', $html);
     $this->render(array('layout' => 'default'));
 }
 /**
  * getAuditInfo - gets additional audit trail information by looking up foreign keys.
  *
  * @param	string	Name of a particular model.
  * @param	int		Id of a record in that particular model.
  * @return 	array 	Information related to $model_name and $id.
  **/
 function getAuditInfo($model_name, $id)
 {
     // checks for deleted and non-deleted records using special field
     $info = false;
     $fctrl =& NController::singleton($model_name);
     if ($fctrl && ($fmodel =& $fctrl->getDefaultModel())) {
         $fmodel->reset();
         if (!$fmodel->get($id)) {
             $fmodel->reset();
             $fields = $fmodel->fields();
             if (in_array('cms_deleted', $fields)) {
                 $fmodel->cms_deleted = 1;
             }
             $fmodel->get($id);
         }
         $info = $fmodel->{$fmodel->primaryKey()} ? $fmodel->toArray() : false;
         if ($info && (!isset($info['_headline']) || !$info['_headline'])) {
             $info['_headline'] = $fmodel->makeHeadline();
         }
         unset($fmodel);
     }
     return $info;
 }
 function viewlist($parameter = null)
 {
     $this->auto_render = false;
     $wusers_ctrl =& NController::singleton('workflow_users');
     include_once 'controller/form.php';
     $this->base_dir = APP_DIR;
     $model =& $this->loadModel($this->name);
     $pk = $model->primaryKey();
     if ($model) {
         if ($parameter) {
             $model->{$model->primaryKey()} = $parameter;
         }
         $model->find();
         $rows = $model->fetchAll(true);
         $wusers_model =& $wusers_ctrl->loadModel($wusers_ctrl->name);
         $workflows = '';
         // put the _headline variable in for the viewlist template
         foreach ($rows as $key => $workflow_group) {
             $cform = new ControllerForm($wusers_ctrl, $wusers_model);
             $form =& $cform->getForm('add_person_form_' . $workflow_group[$pk]);
             $form->removeElement('workflow_group_id');
             $form->setDefaults(array('workflow_group_id' => $workflow_group[$pk]));
             $form->addElement('hidden', 'workflow_group_id', $workflow_group[$pk]);
             $form->addElement('hidden', '_referer', urlencode($_SERVER['REQUEST_URI']));
             $cform->makeRemoteForm(array('url' => array('controller' => 'workflow_users', 'action' => 'add_user'), 'loading' => 'workflowManager.addUserLoading(request, ' . $workflow_group[$pk] . ')', 'complete' => 'workflowManager.onAddUser(request, ' . $workflow_group[$pk] . ')'));
             if ($form->validate()) {
                 $fields = $wusers_model->fields();
                 if (in_array('cms_created', $fields)) {
                     $wusers_model->cms_created = $model->now();
                 }
                 if (in_array('cms_modified', $fields)) {
                     $wusers_model->cms_modified = $model->now();
                 }
                 // set the user id if it's applicable and available
                 if (in_array('cms_modified_by_user', $fields)) {
                     $wusers_model->cms_modified_by_user = isset($this->_auth) && is_object($this->_auth) ? $this->_auth->currentUserID() : 0;
                 }
                 $success = $form->process(array($cform, 'processForm'));
             }
             $headline = $model->getHeadline();
             if (!empty($headline)) {
                 if (is_array($headline)) {
                     $workflow_group['_headline'] = '';
                     foreach ($headline as $row) {
                         $workflow_group['_headline'] .= $workflow_group['_headline'] ? ' - ' : '';
                         $workflow_group['_headline'] .= $workflow_group[$row];
                     }
                 } else {
                     $workflow_group['_headline'] = $workflow_group[$headline];
                 }
             } else {
                 $workflow_group['_headline'] = $workflow_group['cms_headline'];
             }
             $workflow_group['_users'] = array();
             $wusers_model->reset();
             $wusers_model->workflow_group_id = $workflow_group[$pk];
             if ($wusers_model->find()) {
                 while ($wusers_model->fetch()) {
                     $user_model =& $wusers_model->getLink('user_id', 'cms_auth');
                     if ($user_model) {
                         $user = $wusers_model->toArray();
                         $user['real_name'] = $user_model->real_name;
                         $workflow_group['_users'][] = $user;
                     }
                 }
             }
             $workflow_group['asset'] = $this->name;
             $workflow_group['add_user_form'] = $form->toHTML();
             $this->set($workflow_group);
             $workflows .= $this->render(array('action' => 'workflow_group', 'return' => true));
             unset($form);
             unset($cform);
         }
         $this->set(array('asset' => $this->name, 'workflows' => $workflows));
         $main_content = $this->render(array('return' => true));
         $sidebar_content = $this->render(array('action' => 'workflow_description', 'return' => true));
     }
     $this->renderLayout('default', $main_content, $sidebar_content);
 }
示例#9
0
 function postProcessForm(&$values)
 {
     $model =& $this->getDefaultModel();
     $pk = $model->primaryKey();
     // fix the paths for navigation
     // if (on insert or if changed path on update)
     $this->fixPaths($model->{$pk});
     // move all the old content to the current template
     // into matching template containers
     if (isset($values['mv_content'])) {
         $page_content =& NController::singleton('page_content');
         $page_content->changeTemplate($model->{$pk}, $model->page_template_id);
     }
     // delete general caches
     include_once 'n_cache.php';
     NCache::removeMenu();
     NCache::removeTreeAsSelect();
     NCache::removeJavascript($model->{$pk});
     // REMOVE PAGE CACHE
     $this->deletePageCache($model->{$pk});
     // REMOVE PARENT PAGE CACHE (for child links, etc);
     if ($this->action == 'create') {
         // load a new one
         $new_model =& NModel::factory($this->name);
         $parent_id = $new_model->getParent($model->{$pk});
         unset($new_model);
     } else {
         // user the existing model to find the parent
         $parent_id = $model->getParent($model->{$pk});
     }
     $this->deletePageCache($parent_id);
     // remove the site admin cache
     $site_admin =& NController::singleton('site_admin');
     $site_admin->deleteCache();
     unset($site_admin);
     if ($this->action == 'delete') {
         $this->flash->set('notice', 'Your page has been deleted.');
     } else {
         $this->flash->set('notice', 'Your page has been saved.');
     }
     parent::postProcessForm($values);
 }
 function siteAdminList($id = null)
 {
     // set view caching to false so as to not cache every item
     $this->view_caching = false;
     $page_ctrl =& NController::singleton('page');
     $model =& $page_ctrl->getDefaultModel();
     $model->reset();
     $pk = $model->primaryKey();
     $html = '';
     $model->parent_id = $id ? (int) $id : 'null';
     if ($model->find()) {
         $this->set('reorder', $id == 0 ? false : true);
         $this->set('parent_id', $id);
         $html .= $this->render(array('action' => 'site_admin_list_start', 'return' => true));
         $i = 0;
         $assigns['_referer'] = urlencode(NServer::env('REQUEST_URI'));
         $pages =& $model->fetchAll();
         foreach ($pages as $page) {
             $page_edit = false;
             $surfedit = false;
             switch ($this->_auth->getAuthData('user_level')) {
                 case N_USER_EDITOR:
                     $surfedit = true;
                     break;
                 case N_USER_ADMIN:
                 case N_USER_ROOT:
                     $page_edit = true;
                     $surfedit = true;
                     break;
             }
             if (SITE_WORKFLOW) {
                 $assigns['workflow'] = '';
                 $workflow =& NController::singleton('workflow');
                 if ($workflow_group_model =& $workflow->getWorkflowGroup($page)) {
                     $user_rights = $workflow->getWorkflowUserRights($page);
                     if ($user_rights & WORKFLOW_RIGHT_EDIT) {
                         $surfedit = true;
                     }
                     $assigns['workflow'] = $workflow_group_model->workflow_title;
                 }
             }
             $assigns['id'] = $page->{$pk};
             $assigns['title'] = $page->title;
             $assigns['active'] = $page->active;
             $assigns['visible'] = $page->visible;
             $assigns['page_edit'] = $page_edit;
             $assigns['surfedit'] = $surfedit;
             $assigns['odd_or_even'] = $i % 2 == 0 ? 'even' : 'odd';
             $this->set($assigns);
             $html .= $this->render(array('action' => 'sitemap_list_item', 'return' => true));
             $i++;
             $html .= $this->siteAdminList($page->{$pk});
         }
         unset($pages);
         $html .= $this->render(array('action' => 'site_admin_list_end', 'return' => true));
     }
     unset($model, $page_ctrl);
     return $html;
 }
示例#11
0
 function processForm($values)
 {
     $this->controller->preProcessForm($values);
     $model =& $this->model;
     $pk = $model->primaryKey();
     if (!$pk) {
         // TODO: raise error - can't store data if there's no primary key
         return false;
     }
     $table = $model->table();
     $fields = $model->fields();
     $action = 'update';
     if (!isset($model->{$pk}) || !strlen($model->{$pk})) {
         $action = 'insert';
     }
     // setup for file uploads
     $cms_files = array();
     $files = array();
     if (isset($_FILES) && is_array($_FILES)) {
         $form =& $this->form;
         foreach ($_FILES as $field => $value) {
             $el =& $form->getElement($field);
             if ($el->getType() == 'file' || $el->getType() == 'cms_file') {
                 $values[$field] = null;
                 if ($el->getType() == 'cms_file') {
                     $cms_files[$field] =& $el;
                 }
                 if (isset($_FILES[$field]['tmp_name']) && is_uploaded_file($_FILES[$field]['tmp_name'])) {
                     $files[$field] = array('type' => $el->getType(), 'upload_dir' => isset($el->_options['upload_dir']) ? $el->_options['upload_dir'] : UPLOAD_DIR, 'value' => $value);
                 } else {
                     $values[$field] = isset($this->_do->{$field}) ? $this->_do->{$field} : '';
                 }
             }
         }
     }
     foreach ($cms_files as $field => $el) {
         if (isset($values[$field . '__remove']) && $values[$field . '__remove']) {
             $values[$field] = '';
             if (isset($files[$field])) {
                 unset($files[$field]);
                 // so it doesn't get processed and uploaded after the fact
             }
         } else {
             if (isset($values[$field . '__current']) && $values[$field . '__current']) {
                 $values[$field] = $values[$field . '__current'];
             }
         }
     }
     // pull in any boolean fields that weren't passed and should therefore be 0
     foreach ($table as $field => $def) {
         if ($def & N_DAO_BOOL && !preg_match('/^cms_/', $field)) {
             // if the field is being ignored, then leave the value as what it is
             if (in_array($field, $model->form_ignore_fields)) {
                 continue;
             }
             $values[$field] = isset($values[$field]) ? 1 : 0;
         }
     }
     // deal with general values
     foreach ($values as $field => $val) {
         if (!in_array($field, $fields)) {
             continue;
         }
         $def = $table[$field];
         switch (true) {
             case ($def & N_DAO_DATE || $def & N_DAO_TIME) && is_array($val):
                 $val = NDate::arrayToDate($val);
                 if (!($def & N_DAO_NOTNULL)) {
                     if ($def & N_DAO_DATE || $def & N_DAO_TIME) {
                         if (!NDate::validDateTime($val)) {
                             $val = 'null';
                         }
                     }
                 }
                 break;
         }
         $model->{$field} = $val;
     }
     // set the autoheadline if it exists and wasn't set manually
     if (in_array('cms_headline', $fields) && !$values['cms_headline'] && $model->getHeadline()) {
         $model->cms_headline = $model->makeHeadline('-');
     }
     if ($action == 'update') {
         $this->processFiles($values, $files);
         foreach ($files as $field => $val) {
             if (!in_array($field, $fields)) {
                 continue;
             }
             $model->{$field} = $values[$field];
         }
         $page_content_id = $this->controller->getParam('page_content_id') ? $this->controller->getParam('page_content_id') : false;
         if ($page_content_id) {
             $page_content =& NController::singleton('page_content');
             $page_content_model =& $page_content->getDefaultModel();
             $page_content_model->get($page_content_id);
         }
         // set up timed contnt values if they are there
         if (isset($values['timed_start'])) {
             $values['timed_start'] = NDate::arrayToDate($values['timed_start']);
             if (!NDate::validDateTime($values['timed_start'])) {
                 $values['timed_start'] = 'null';
             }
         }
         if (isset($values['timed_end'])) {
             $values['timed_end'] = NDate::arrayToDate($values['timed_end']);
             if (!NDate::validDateTime($values['timed_end'])) {
                 $values['timed_end'] = 'null';
             }
         }
         // check for workflow
         if (SITE_WORKFLOW && isset($values['__submit_workflow__'])) {
             $page_content =& NController::factory('page_content');
             if (!$page_content_id) {
                 // then find the page we're attached to
                 $page_content_model =& $page_content->getDefaultModel();
                 $page_content_model->content_asset = $this->controller->name;
                 $page_content_model->content_asset_id = $model->{$pk};
                 if ($page_content_model->find(null, true)) {
                     $page_content_id = $page_content_model->{$page_content_model->primaryKey()};
                 }
             }
             if ($page_content_id) {
                 $page_model = $page_content_model->getLink('page_id', 'page');
                 $page_id = $page_model->{$page_model->primaryKey()};
                 // remove the draft and update the content
                 // delete the draft record
                 $this->controller->deleteDraft();
                 // Pull a fresh copy of the asset model and set the draft to 0
                 // so we don't update with the new content yet
                 $asset_model =& NModel::factory($this->controller->name);
                 $asset_model->get($model->{$pk});
                 $asset_model->cms_draft = 0;
                 $asset_model->update();
             }
             unset($page_content);
             // save the workflow
             $workflow =& NController::factory('workflow');
             $workflow_group_model = $workflow->getWorkflowGroup($page_model);
             // set values for saveWorkflow()
             $workflow_values = array();
             $workflow_values['page_content_id'] = $page_content_model->{$page_content_model->primaryKey()};
             $workflow_values['workflow_group_id'] = $workflow_group_model->{$workflow_group_model->primaryKey()};
             // add timed content
             $workflow_values['timed_start'] = $values['timed_start'];
             $workflow_values['timed_end'] = $values['timed_end'];
             // unset the timed content values so they don't get pushed into page_content
             unset($values['timed_start'], $values['timed_end']);
             $ret = $workflow->saveWorkflow($workflow_values, WORKFLOW_ACTION_EDIT, $this->controller);
         } else {
             if ($page_content_id) {
                 $page_content_model->timed_start = $values['timed_start'];
                 $page_content_model->timed_end = $values['timed_end'];
                 $page_content_model->col_xs = $values['col_xs'];
                 $page_content_model->col_sm = $values['col_sm'];
                 $page_content_model->col_md = $values['col_md'];
                 $page_content_model->col_lg = $values['col_lg'];
                 $page_content_model->row_xs = $values['row_xs'];
                 $page_content_model->row_sm = $values['row_sm'];
                 $page_content_model->row_md = $values['row_md'];
                 $page_content_model->row_lg = $values['row_lg'];
                 $page_content_model->offset_col_xs = $values['offset_col_xs'];
                 $page_content_model->offset_col_sm = $values['offset_col_sm'];
                 $page_content_model->offset_col_md = $values['offset_col_md'];
                 $page_content_model->offset_col_lg = $values['offset_col_lg'];
                 $page_content_model->offset_row_xs = $values['offset_row_xs'];
                 $page_content_model->offset_row_sm = $values['offset_row_sm'];
                 $page_content_model->offset_row_md = $values['offset_row_md'];
                 $page_content_model->offset_row_lg = $values['offset_row_lg'];
                 $page_content_model->pull_xs = $values['pull_xs'];
                 $page_content_model->pull_sm = $values['pull_sm'];
                 $page_content_model->pull_md = $values['pull_md'];
                 $page_content_model->pull_lg = $values['pull_lg'];
                 $page_content_model->gutter_xs = $values['gutter_xs'];
                 $page_content_model->gutter_sm = $values['gutter_sm'];
                 $page_content_model->gutter_md = $values['gutter_md'];
                 $page_content_model->gutter_lg = $values['gutter_lg'];
                 $page_content_model->update();
             }
         }
         // check for drafts
         if (SITE_DRAFTS) {
             if (isset($table['cms_draft']) && isset($values['__submit_draft__'])) {
                 $ret = $this->controller->saveDraft();
                 // update the headline immediately if it exists
                 if (isset($table['cms_headline'])) {
                     $tmp_model =& NModel::factory($this->controller->name);
                     if ($tmp_model && $tmp_model->get($values[$pk])) {
                         $tmp_model->cms_headline = $values['cms_headline'];
                         $tmp_model->update();
                     }
                     unset($tmp_model);
                 }
             }
         }
         if (isset($values['__submit__'])) {
             if ($this->controller->versioning == true) {
                 if (!isset($values['__skip_versioning__'])) {
                     $this->controller->debug('Inserting new version for ' . $model->tableName() . ': ' . $model->{$pk}, 'VERSION');
                     $version_id = $this->controller->insertVersion();
                 }
             }
             // if it's being saved normally (no draft), make sure it's not marked as a draft
             $model->cms_draft = 0;
             $ret = $model->update();
             if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL && isset($this->controller->_auth)) {
                 // audit trail
                 $audit_trail =& NController::factory('audit_trail');
                 $audit_trail_values = array();
                 $audit_trail_values['asset'] = $this->controller->name;
                 $audit_trail_values['asset_id'] = $model->{$pk};
                 $audit_trail_values['action_taken'] = AUDIT_ACTION_UPDATE;
                 if (isset($page_content_id)) {
                     $audit_trail_values['page_content_id'] = $page_content_id;
                 }
                 if (isset($page_id)) {
                     $audit_trail_values['page_id'] = $page_id;
                 }
                 $audit_trail->insert($audit_trail_values);
                 unset($audit_trail);
             }
             if (SITE_DRAFTS) {
                 // delete any draft records
                 $this->controller->deleteDraft();
             }
             // remove all linked page caches
             $page =& NController::factory('page');
             $page_content_model =& NModel::factory('page_content');
             $page_content_model->content_asset = $this->controller->name;
             $page_content_model->content_asset_id = $values[$pk];
             if ($page_content_model->find()) {
                 while ($page_content_model->fetch()) {
                     $page->deletePageCache($page_content_model->page_id);
                 }
             }
             unset($page);
             unset($page_content_model);
         }
     } else {
         $draft = false;
         if (SITE_DRAFTS && isset($table['cms_draft']) && isset($values['__submit_draft__'])) {
             $model->cms_draft = 1;
         }
         $id = $model->insert();
         $this->processFiles($values, $files);
         foreach ($files as $field => $val) {
             if (!in_array($field, $fields)) {
                 continue;
             }
             $model->{$field} = $values[$field];
         }
         if (SITE_DRAFTS && isset($table['cms_draft']) && isset($values['__submit_draft__'])) {
             // set draft to true after the draft is saved
             $draft = $this->controller->saveDraft();
         }
         $model->update();
         if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL && isset($this->controller->_auth)) {
             // audit trail
             $audit_trail =& NController::factory('audit_trail');
             $audit_trail_values = array();
             $audit_trail_values['asset'] = $this->controller->name;
             $audit_trail_values['asset_id'] = $model->{$pk};
             $audit_trail_values['action_taken'] = AUDIT_ACTION_INSERT;
             if (isset($page_content_id)) {
                 $audit_trail_values['page_content_id'] = $page_content_id;
             }
             if (isset($page_id)) {
                 $audit_trail_values['page_id'] = $page_id;
             }
             $audit_trail->insert($audit_trail_values);
             unset($audit_trail);
         }
         $ret = $id;
     }
     if ($ret) {
         $this->controller->postProcessForm($values);
     }
     if (isset($values['_referer'])) {
         header('Location:' . urldecode($values['_referer']));
         exit;
     }
     return $ret;
 }