function test_monthly_date_start_end()
 {
     $day = false;
     $month = 10;
     $year = 2000;
     $month_arg = array('Y' => $year, 'F' => $month, 'd' => $day);
     $date = AuditTrailController::dateStartEnd($month_arg);
     $this->assertEquals($date['used'], "{$year}-{$month}-1", 'Month used should match first day of month given eg: 2000-10-01');
     $this->assertEquals($date['month'], true, 'With day set to false, should set the month flag to true');
     $month_start = NDate::convertTimeToUTC(date('Y-m-d', strtotime("{$year}-{$month}-1")) . ' 00:00:00', '%Y-%m-%d %H:%M:%S');
     $this->assertEquals($date['start'], $month_start, 'Month start should be UTC version of first day of month start');
     $month_len = date('t', strtotime("{$year}-{$month}-1"));
     $month_end = NDate::convertTimeToUTC(date('Y-m-d', strtotime("{$year}-{$month}-{$month_len}")) . ' 23:59:59', '%Y-%m-%d %H:%M:%S');
     $this->assertEquals($date['end'], $month_end, 'Month end should be UTC version of last day of month end');
 }
 function _removeTimedContent($records)
 {
     $cleaned_records = array();
     $time = date("Y-m-d G:i:s", time());
     $time = NDate::convertTimeToUTC($time);
     foreach ($records as $record) {
         // If they're both null - just add the record and skip the rest.
         if (is_null($record['timed_start']) && is_null($record['timed_end']) || $record['timed_start'] == '0000-00-00 00:00:00') {
             $cleaned_records[] = $record;
             continue;
         }
         if (!is_null($record['timed_start']) && $record['timed_start'] > $time) {
             continue;
         }
         if (!is_null($record['timed_end']) && $record['timed_end'] < $time) {
             continue;
         }
         $cleaned_records[] = $record;
     }
     return $cleaned_records;
 }
 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'));
 }
 function dateStartEnd($params = false)
 {
     $y = isset($params['Y']) && $params['Y'] ? $params['Y'] : false;
     $m = isset($params['F']) && $params['F'] ? $params['F'] : false;
     $d = isset($params['d']) && $params['d'] ? $params['d'] : false;
     $date = array();
     $date['month'] = false;
     if ($y && $d && $m) {
         // Fully qualified
         $date_arg = date('Y-m-d', strtotime("{$y}-{$m}-{$d}"));
         $date['start'] = NDate::convertTimeToUTC($date_arg . ' 00:00:00', '%Y-%m-%d %H:%M:%S');
         $date['end'] = NDate::convertTimeToUTC($date_arg . ' 23:59:59', '%Y-%m-%d %H:%M:%S');
         $date['used'] = $date_arg;
         return $date;
     }
     if (!$params['d'] && ($y && $params['F'])) {
         // One Month
         $date_arg = date('Y-m-d', strtotime("{$y}-{$m}-1"));
         $days_in_month = date('t', strtotime($date_arg));
         $month_end = date('Y-m-d', strtotime("{$y}-{$m}-{$days_in_month}"));
         $date['start'] = NDate::convertTimeToUTC($date_arg . ' 00:00:00', '%Y-%m-%d %H:%M:%S');
         $date['end'] = NDate::convertTimeToUTC($month_end . ' 23:59:59', '%Y-%m-%d %H:%M:%S');
         $date['used'] = "{$y}-{$m}-1";
         $date['month'] = true;
         return $date;
     }
     // Default to one day: today
     $date['start'] = NDate::convertTimeToUTC(date('Y-m-d') . ' 00:00:00', '%Y-%m-%d %H:%M:%S');
     $date['end'] = NDate::convertTimeToUTC(date('Y-m-d') . ' 23:59:59', '%Y-%m-%d %H:%M:%S');
     $date['used'] = date('Y-m-d');
     return $date;
 }
示例#5
0
 function convertTimeToUTC($field, $value)
 {
     // make sure the value is there and doesn't equal "null"
     // "null" is a special-case which gets changed to NULL in the sql
     if ($value && $value != 'null') {
         $table = $this->table();
         $def = $table[$field];
         // can put DB-specific date formatting here...
         $format = '%Y-%m-%d %H:%M:%S';
         if (N_DAO_TIME & $def && !(N_DAO_DATE & $def)) {
             // we can get away with strtotime() on time values (no date)
             $value = date('Y-m-d H:i:s', strtotime($value));
             $format = '%H:%M:%S';
         }
         include_once 'n_date.php';
         $rvalue = NDate::convertTimeToUTC($value, $format);
         if (!$rvalue) {
             // if it's false then pass it back or string nullify it (which is handled in insert/update)
             $value = N_DAO_NOTNULL & $def ? $value : 'null';
         } else {
             $value = $rvalue;
         }
     }
     return $value;
 }