public function rebuild($start_date = null, $end_date = null) { if (!$start_date) { $start_date = config_option('last_sharing_table_rebuild'); } if ($start_date instanceof DateTimeValue) { $start_date = $start_date->toMySQL(); } if ($end_date instanceof DateTimeValue) { $end_date = $end_date->toMySQL(); } if ($end_date) { $end_cond = "AND updated_on <= '{$end_date}'"; } try { $object_ids = Objects::instance()->findAll(array('id' => true, "conditions" => "updated_on >= '{$start_date}' {$end_cond}")); $obj_count = 0; DB::beginWork(); foreach ($object_ids as $id) { $obj = Objects::findObject($id); if ($obj instanceof ContentDataObject) { $obj->addToSharingTable(); $obj_count++; } } set_config_option('last_sharing_table_rebuild', DateTimeValueLib::now()->toMySQL()); DB::commit(); } catch (Exception $e) { DB::rollback(); Logger::log("Failed to rebuild sharing table: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString()); } return $obj_count; }
/** * Check if there is a new version of application available * * @param boolean $force When forced check will always construct the versions feed object * try to fech the data and check for a new version. Version feed object is also returned * @return VersionFeed In case of error this function will return false */ static function check($force = true) { $allow_url_fopen = strtolower(ini_get('allow_url_fopen')); if (function_exists('simplexml_load_file') && ($allow_url_fopen == '1' || $allow_url_fopen == 'on')) { // Execute once a day, if not forced check if we need to execute it now if (!$force) { if (config_option('upgrade_last_check_new_version', false)) { return true; // already have it checked and already have a new version } // if $last_check = config_option('upgrade_last_check_datetime'); if ($last_check instanceof DateTimeValue && $last_check->getTimestamp() + 86400 > DateTimeValueLib::now()->getTimestamp()) { return true; // checked in the last day } // if } // if try { $versions_feed = new VersionsFeed(); set_config_option('upgrade_last_check_datetime', DateTimeValueLib::now()); set_config_option('upgrade_last_check_new_version', $versions_feed->hasNewVersions(product_version())); return $force ? $versions_feed : true; } catch (Exception $e) { return false; } // try } else { set_config_option('upgrade_check_enabled', false); return false; } // if }
function purge_trash() { Env::useHelper("permissions"); $days = config_option("days_on_trash", 0); $count = 0; if ($days > 0) { $date = DateTimeValueLib::now()->add("d", -$days); $objects = Objects::findAll(array("conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ?", $date), "limit" => 100)); foreach ($objects as $object) { $concrete_object = Objects::findObject($object->getId()); if (!$concrete_object instanceof ContentDataObject) { continue; } if ($concrete_object instanceof MailContent && $concrete_object->getIsDeleted() > 0) { continue; } try { DB::beginWork(); if ($concrete_object instanceof MailContent) { $concrete_object->delete(false); } else { $concrete_object->delete(); } ApplicationLogs::createLog($concrete_object, ApplicationLogs::ACTION_DELETE); DB::commit(); $count++; } catch (Exception $e) { DB::rollback(); Logger::log("Error delting object in purge_trash: " . $e->getMessage(), Logger::ERROR); } } } return $count; }
function cvs_total_task_times_table($objects, $pad_str, $options, $group_name, &$sub_total = 0) { echo lang('date') . ';'; echo lang('title') . ';'; echo lang('description') . ';'; echo lang('person') . ';'; echo lang('time') .'('.lang('hours').')'. ';'; echo "\n"; $sub_total = 0; foreach ($objects as $ts) { echo $pad_str . format_date($ts->getStartTime()) . ';'; $name = ($ts->getRelObjectId() == 0 ? $ts->getObjectName() : $ts->getRelObject()->getObjectName()); $name = str_replace("\r", " ", str_replace("\n", " ", str_replace("\r\n", " ", $name))); echo $name . ';'; $desc = $ts->getDescription(); $desc = str_replace("\r", " ", str_replace("\n", " ", str_replace("\r\n", " ", $desc))); $desc = '"'.$desc.'"'; echo $desc .';'; echo ($ts->getUser() instanceof Contact ? $ts->getUser()->getObjectName() : '') .';'; $lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now()); $mystring = DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "m", 60, $ts->getSubtract()); $resultado = ereg_replace("[^0-9]", "", $mystring); $resultado = round(($resultado/60),5); echo $resultado; $sub_total += $resultado; echo "\n"; } }
function getDueReminders($type = null) { if (isset($type)) { $extra = ' AND `type` = ' . DB::escape($type); } else { $extra = ""; } return ObjectReminders::findAll(array('conditions' => array("`date` > '0000-00-00 00:00:00' AND `date` < ?" . $extra, DateTimeValueLib::now()), 'limit' => config_option('cron reminder limit', 100))); }
/** * Returnst true if this application log was made yesterday * * @param void * @return boolean */ function isYesterday() { $created_on = $this->getCreatedOn(); if (!$created_on instanceof DateTimeValue) { return false; } $day_after = $created_on->advance(24 * 60 * 60, false); $now = DateTimeValueLib::now(); return $now->getDay() == $day_after->getDay() && $now->getMonth() == $day_after->getMonth() && $now->getYear() == $day_after->getYear(); }
/** * Return all users that was active in past $active_in minutes (defautl is 15 minutes) * * @access public * @param integer $active_in * @return array */ static function getWhoIsOnline($active_in = 15) { if ((int) $active_in < 1) { $active_in = 15; } $datetime = DateTimeValueLib::now(); $datetime->advance(-1 * $active_in * 60); return Users::findAll(array('conditions' => array('`last_activity` > ?', $datetime))); // findAll }
function total_task_times_print_table($objects, $left, $options, $group_name, &$sub_total = 0, &$sub_total_billing = 0, &$sub_total_estimated = 0) { echo '<div style="padding-left:' . $left . 'px;">'; echo '<table class="reporting-table"><tr class="reporting-table-heading">'; echo '<th>' . lang('date') . '</th>'; echo '<th>' . lang('title') . '</th>'; echo '<th>' . lang('description') . '</th>'; echo '<th>' . lang('person') . '</th>'; if (array_var($options, 'show_billing') == 'checked') { echo '<th class="right">' . lang('billing') . '</th>'; } echo '<th class="right">' . lang('time') . '</th>'; if ((array_var($options, 'timeslot_type') == 0 || array_var($options, 'timeslot_type') == 2) && array_var($options, 'show_estimated_time')) { echo '<th class="right">' . lang('estimated') . '</th>'; } echo '</tr>'; $sub_total = 0; $tasks = array(); $alt_cls = ""; foreach ($objects as $ts) { /* @var $ts Timeslot */ echo "<tr {$alt_cls}>"; echo "<td class='date'>" . format_date($ts->getStartTime()) . "</td>"; echo "<td class='name'>" . ($ts->getRelObjectId() == 0 ? clean($ts->getObjectName()) : clean($ts->getRelObject()->getObjectName())) . "</td>"; echo "<td class='name'>" . nl2br(clean($ts->getDescription())) . "</td>"; echo "<td class='person'>" . clean($ts->getUser() instanceof Contact ? $ts->getUser()->getObjectName() : '') . "</td>"; if (array_var($options, 'show_billing') == 'checked') { if ($ts->getIsFixedBilling()) { echo "<td class='nobr right'>" . config_option('currency_code', '$') . " " . number_format($ts->getFixedBilling(), 2) . "</td>"; $sub_total_billing += $ts->getFixedBilling(); } else { $min = $ts->getMinutes(); echo "<td class='nobr right'>" . config_option('currency_code', '$') . " " . number_format($ts->getHourlyBilling() / 60 * $min, 2) . "</td>"; $sub_total_billing += $ts->getHourlyBilling() / 60 * $min; } } $lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now()); echo "<td class='time nobr right'>" . DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "hm", 60, $ts->getSubtract()) . "</td>"; if ((array_var($options, 'timeslot_type') == 0 || array_var($options, 'timeslot_type') == 2) && $ts->getRelObject() instanceof ProjectTask && array_var($options, 'show_estimated_time')) { echo "<td class='time nobr right'>" . DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($ts->getRelObject()->getTimeEstimate() * 60), 'hm', 60) . "</td>"; $task = $ts->getRelObject(); //check if I have the estimated time of this task if (!in_array($task->getId(), $tasks)) { $sub_total_estimated += $task->getTimeEstimate(); } $tasks[] = $task->getId(); } elseif ((array_var($options, 'timeslot_type') == 0 || array_var($options, 'timeslot_type') == 2) && array_var($options, 'show_estimated_time')) { echo "<td class='time nobr right'> 0 </td>"; } echo "</tr>"; $sub_total += $ts->getMinutes(); $alt_cls = $alt_cls == "" ? 'class="alt-row"' : ""; } echo '</table></div>'; }
function getDueEvents($date = null) { if (!$date instanceof DateTimeValue) { $date = DateTimeValueLib::now(); } $events = self::findAll(array('conditions' => array('`date` <= ?', $date))); if (!is_array($events)) { return array(); } return $events; }
function getDueEvents($date = null) { if (defined('REMOVE_AUTOLOADER_BEFORE_CRON') && REMOVE_AUTOLOADER_BEFORE_CRON) { @unlink(CACHE_DIR . "/autoloader.php"); } if (!$date instanceof DateTimeValue) { $date = DateTimeValueLib::now(); } $events = self::findAll(array('conditions' => array('`date` <= ?', $date))); if (!is_array($events)) { return array(); } return $events; }
/** * Return late tickets from active projects given user has access on. * * @param User $user * @return array or null */ function getOpenTicketsByUser(User $user) { $due_date = DateTimeValueLib::now()->beginningOfDay(); $projects = $user->getActiveProjects(); if (!is_array($projects) || !count($projects)) { return null; } $project_ids = array(); foreach ($projects as $project) { $project_ids[] = $project->getId(); } // foreach return self::findAll(array('conditions' => array('`closed_on` = ? AND `project_id` IN (?)', EMPTY_DATETIME, $project_ids), 'order' => '`priority`')); // findAll }
/** * Set cookie value * * @param string $name Variable name * @param mixed $value * @param integer $expiration Number of seconds from current time when this cookie need to expire * @return null */ static function setValue($name, $value, $expiration = null) { $expiration_time = DateTimeValueLib::now(); if ((int) $expiration > 0) { $expiration_time->advance($expiration); } else { $expiration_time->advance(3600); // one hour } // if $path = defined('COOKIE_PATH') ? COOKIE_PATH : '/'; $domain = defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : ''; $secure = defined('COOKIE_SECURE') ? COOKIE_SECURE : false; setcookie($name, $value, $expiration_time->getTimestamp(), $path, $domain, $secure); }
/** * Set cookie value * * @param string $name Variable name * @param mixed $value * @param integer $expiration Number of seconds from current time when this cookie need to expire * @return null */ static function setValue($name, $value, $expiration = null) { $expiration_time = DateTimeValueLib::now(); if ((int) $expiration > 0) { $expiration_time->advance($expiration); } else { $expiration_time->advance(3600); // one hour } // if // if $expiration is null, set the cookie to expire when the session is over $expiration_timestamp = is_null($expiration) ? null : $expiration_time->getTimestamp(); $path = defined('COOKIE_PATH') ? COOKIE_PATH : '/'; $domain = defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : ''; $secure = defined('COOKIE_SECURE') ? COOKIE_SECURE : false; setcookie($name, $value, $expiration_timestamp, $path, $domain, $secure); }
function purge_trash() { Env::useHelper("permissions"); $days = config_option("days_on_trash", 0); $count = 0; if ($days > 0) { $date = DateTimeValueLib::now()->add("d", -$days); $managers = array('Comments', 'Companies', 'Contacts', 'MailContents', 'ProjectCharts', 'ProjectEvents', 'ProjectFiles', 'ProjectFileRevisions', 'ProjectForms', 'ProjectMessages', 'ProjectMilestones', 'ProjectTasks', 'ProjectWebpages'); foreach ($managers as $manager_class) { $manager = new $manager_class(); $prevcount = -1; while ($prevcount != $count) { $prevcount = $count; if ($manager_class == 'MailContents') { $objects = $manager->findAll(array("include_trashed" => true, "conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ? AND `is_deleted` = 0", $date), "limit" => 100)); } else { $objects = $manager->findAll(array("include_trashed" => true, "conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ?", $date), "limit" => 100)); } if (is_array($objects)) { // delete one by one because each one knows what else to delete foreach ($objects as $o) { try { DB::beginWork(); $ws = $o->getWorkspaces(); if ($o instanceof MailContent) { $o->delete(false); } else { $o->delete(); } ApplicationLogs::createLog($o, $ws, ApplicationLogs::ACTION_DELETE); DB::commit(); $count++; } catch (Exception $e) { DB::rollback(); Logger::log("Error deleting object in purge_trash: " . $e->getMessage(), Logger::ERROR); } } } } } } return $count; }
function format_value_to_print_task($value, $type, $textWrapper = '', $dateformat = 'Y-m-d') { switch ($type) { case DATA_TYPE_STRING: if (preg_match(EMAIL_FORMAT, strip_tags($value))) { $formatted = $value; } else { $formatted = $textWrapper . clean($value) . $textWrapper; } break; case DATA_TYPE_INTEGER: $formatted = clean($value); break; case DATA_TYPE_BOOLEAN: $formatted = $value == 1 ? lang('yes') : lang('no'); break; case DATA_TYPE_DATE: if ($value != 0) { if (str_ends_with($value, "00:00:00")) { $dateformat .= " H:i:s"; } $dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value); $formatted = format_date($dtVal, null, 0); } else { $formatted = ''; } break; case DATA_TYPE_DATETIME: if ($value != 0) { $dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value); $formatted = format_date($dtVal, null, 0); } else { $formatted = ''; } break; default: $formatted = $value; } if ($formatted == '') { $formatted = '--'; } return $formatted; }
function cvs_total_task_times_table($objects, $pad_str, $options, $group_name, &$sub_total = 0) { echo lang('date') . ';'; echo lang('title') . ';'; echo lang('description') . ';'; echo lang('person') . ';'; echo lang('time') . ';'; echo "\n"; $sub_total = 0; foreach ($objects as $ts) { echo $pad_str . format_date($ts->getStartTime()) . ';'; echo ($ts->getRelObjectId() == 0 ? clean($ts->getObjectName()) : clean($ts->getRelObject()->getObjectName())) . ';'; echo clean($ts->getDescription()) . ';'; echo clean($ts->getUser()->getObjectName()) . ';'; $lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now()); echo DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "hm", 60, $ts->getSubtract()) . ';'; $sub_total += $ts->getMinutes(); echo "\n"; } }
function formatted_date($css_class, $date, $label) { ?> <div class="<?php echo $css_class; ?> "> <span><?php echo lang('start date'); ?> :</span> <?php if ($date->getYear() > DateTimeValueLib::now()->getYear()) { echo format_date($date, null, 0); } else { echo format_descriptive_date($date, 0); } ?> </div> <?php }
function mail_on_page_load() { //check if have outbox mails $usu = logged_user(); $accounts = MailAccounts::instance()->getMailAccountsByUser($usu); $account_ids = array(); foreach ($accounts as $acc) { $account_ids[] = $acc->getId(); } if (count($account_ids) == 0) { return; } $accounts_sql = " AND account_id IN (" . implode(',', $account_ids) . ")"; $user_pg_ids = $usu->getPermissionGroupIds(); if (count($user_pg_ids) == 0) { return; } $permissions_sql = " AND EXISTS (SELECT sh.group_id FROM " . TABLE_PREFIX . "sharing_table sh WHERE sh.object_id=o.id AND sh.group_id IN (" . implode(',', $user_pg_ids) . "))"; $conditions = array("conditions" => array("`state` >= 200 AND (`state`%2 = 0) AND `archived_on`=0 AND `trashed_on`=0 {$accounts_sql} {$permissions_sql} AND `created_by_id` =" . $usu->getId())); $outbox_mails = MailContents::findAll($conditions); if ($outbox_mails != null) { if (count($outbox_mails) >= 1) { $arguments = array("conditions" => array("`context` LIKE 'mails_in_outbox%' AND `contact_id` = " . $usu->getId() . ";")); $exist_reminder = ObjectReminders::find($arguments); if (!(count($exist_reminder) > 0)) { $reminder = new ObjectReminder(); $minutes = 0; $reminder->setMinutesBefore($minutes); $reminder->setType("reminder_popup"); $reminder->setContext("mails_in_outbox " . count($outbox_mails)); $reminder->setObject($usu); $reminder->setUserId($usu->getId()); $reminder->setDate(DateTimeValueLib::now()); $reminder->save(); } } } }
/** * Return late tickets that are assigned to the user * * @param User $user * @param boolean $include_company includes tickets assigned to whole company * @return array */ function getLateTicketsByUser(User $user, $include_company = false) { $due_date = DateTimeValueLib::now()->beginningOfDay(); $projects = $user->getActiveProjects(); if (!is_array($projects) || !count($projects)) { return null; } // if $project_ids = array(); foreach ($projects as $project) { $project_ids[] = $project->getId(); } // foreach // TODO This request contains a hard-coded value for status. Might need to be changed // if ticket properties are made more generic if ($include_company) { return self::findAll(array('conditions' => array('(`assigned_to_user_id` = ? OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `project_id` IN (?) AND `state` <> ?', $user->getId(), 0, $user->getCompanyId(), $project_ids, 'closed'), 'order' => '`state` ASC')); // findAll } else { return self::findAll(array('conditions' => array('`assigned_to_user_id` = ? AND `project_id` IN (?) AND `state` <> ?', $user->getId(), $project_ids, 'closed'), 'order' => '`state` ASC')); // findAll } // if }
/** * Return number of days that is left * * @access public * @param void * @return integer */ function getLeftInDays() { $due_date_start = $this->getDueDate()->endOfDay(); return floor(abs($due_date_start->getTimestamp() - DateTimeValueLib::now()->beginningOfDay()->getTimestamp()) / 86400); }
/** * Checck out file * * @param bool $autoCheckOut Is true when the file was automatically checked out on edit * @param User $user If null, logged user is used * @return boolean */ function checkOut($autoCheckOut = false, $user = null) { if (!$user) { $user = logged_user(); } if ($this->getCheckedOutById() != 0 && !$user->isAdministrator()) { return false; } $this->setWasAutoCheckedAuto($autoCheckOut); $this->setCheckedOutById($user->getId()); $this->setCheckedOutOn(DateTimeValueLib::now()); $this->setMarkTimestamps(false); $this->save(); return true; }
if ($milestone->getIsTemplate()) { add_page_action(lang('new milestone from template'), get_url("milestone", "copy_milestone", array("id" => $milestone->getId())), 'ico-copy'); } else { add_page_action(lang('copy milestone'), get_url("milestone", "copy_milestone", array("id" => $milestone->getId())), 'ico-copy'); if (can_manage_templates(logged_user())) { add_page_action(lang('add to a template'), get_url("template", "add_to", array("manager" => 'ProjectMilestones', "id" => $milestone->getId())), 'ico-template'); } } } ?> <div style="padding:7px"> <div class="milestone"> <?php $content = ''; if ($milestone->getDueDate()->getYear() > DateTimeValueLib::now()->getYear()) { $content = '<div class="dueDate"><b>' . lang('due date') . ':</b> ' . format_date($milestone->getDueDate(), null, 0) . '</div>'; } else { $content = '<div class="dueDate"><b>' . lang('due date') . ':</b> ' . format_descriptive_date($milestone->getDueDate(), 0) . '</div>'; } // if if ($milestone->getDescription()) { $content .= '<fieldset><legend>' . lang('description') . '</legend>' . escape_html_whitespace(convert_to_links(clean($milestone->getDescription()))) . '</fieldset>'; } $openSubtasks = $milestone->getOpenSubTasks(); if (is_array($openSubtasks)) { // $content .= '<p>' . lang('task lists') . ':</p><ul>'; //show open sub task list $content .= '<br/><table style="border:1px solid #717FA1;width:100%; padding-left:10px;"><tr><th style="padding-left:10px;padding-top:4px;padding-bottom:4px;background-color:#E8EDF7;font-size:120%;font-weight:bolder;color:#717FA1;width:100%;">' . lang("view open tasks") . '</th></tr><tr><td style="padding-left:10px;"> <div class="openTasks"> <table class="blank">';
function format_value_to_print($col, $value, $type, $obj_type_id, $textWrapper = '', $dateformat = 'Y-m-d') { switch ($type) { case DATA_TYPE_STRING: if (preg_match(EMAIL_FORMAT, strip_tags($value))) { $formatted = strip_tags($value); } else { $formatted = $textWrapper . clean($value) . $textWrapper; } break; case DATA_TYPE_INTEGER: if ($col == 'priority') { switch ($value) { case 100: $formatted = lang('low priority'); break; case 200: $formatted = lang('normal priority'); break; case 300: $formatted = lang('high priority'); break; case 400: $formatted = lang('urgent priority'); break; default: $formatted = clean($value); } } elseif ($col == 'time_estimate') { if ($value > 0) { $formatted = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($value * 60), 'hm', 60); } else { $formatted = clean($value); } } else { $formatted = clean($value); } break; case DATA_TYPE_BOOLEAN: $formatted = $value == 1 ? lang('yes') : lang('no'); break; case DATA_TYPE_DATE: if ($value != 0) { if (str_ends_with($value, "00:00:00")) { $dateformat .= " H:i:s"; } $dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value); $formatted = format_date($dtVal, null, 0); } else { $formatted = ''; } break; case DATA_TYPE_DATETIME: if ($value != 0) { $dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value); if ($obj_type_id == ProjectEvents::instance()->getObjectTypeId() && $col == 'start') { $formatted = format_datetime($dtVal); } else { $formatted = format_date($dtVal, null, 0); } } else { $formatted = ''; } break; default: $formatted = $value; } if ($formatted == '') { $formatted = '--'; } return $formatted; }
/** * Handle files uploaded using helper forms. This function will return array of uploaded * files when finished * * @param string $files_var_prefix If value of this variable is set only elements in $_FILES * with key starting with $files_var_prefix will be handled * @return array */ static function handleHelperUploads($context, $files_var_prefix = null) { //FIXME return null; if (!isset($_FILES) || !is_array($_FILES) || !count($_FILES)) { return null; // no files to handle } $uploaded_files = array(); foreach ($_FILES as $uploaded_file_name => $uploaded_file) { if (trim($files_var_prefix) != '' && !str_starts_with($uploaded_file_name, $files_var_prefix)) { continue; } if (!isset($uploaded_file['name']) || !isset($uploaded_file['tmp_name']) || !is_file($uploaded_file['tmp_name'])) { continue; } $uploaded_files[$uploaded_file_name] = $uploaded_file; } if (!count($uploaded_file)) { return null; } $result = array(); // we'll put all files here $expiration_time = DateTimeValueLib::now()->advance(1800, false); foreach ($uploaded_files as $uploaded_file) { $file = new ProjectFile(); $file->setProjectId($project->getId()); $file->setFilename($uploaded_file['name']); $file->setIsVisible(false); $file->setExpirationTime($expiration_time); $file->save(); $file->handleUploadedFile($uploaded_file); // initial version $result[] = $file; } return count($result) ? $result : null; }
/** * This function will return true if this datetime is yesterday * * @param void * @return boolean */ function isYesterday() { $yesterday = DateTimeValueLib::makeFromString('yesterday'); return $this->getDay() == $yesterday->getDay() && $this->getMonth() == $yesterday->getMonth() && $this->getYear() == $yesterday->getYear(); }
function get_member_custom_property_value_for_listing($cp, $member_id, $cp_vals = null) { if (is_null($cp_vals)) { $cp_vals = MemberCustomPropertyValues::getMemberCustomPropertyValues($member_id, $cp->getId()); } $val_to_show = ""; foreach ($cp_vals as $cp_val) { if (in_array($cp->getType(), array('contact', 'user')) && $cp_val instanceof MemberCustomPropertyValue) { $cp_contact = Contacts::findById($cp_val->getValue()); if ($cp_contact instanceof Contact) { $cp_val->setValue($cp_contact->getObjectName()); } else { $cp_val->setValue(""); } } if ($cp->getType() == 'date' && $cp_val instanceof MemberCustomPropertyValue) { $format = user_config_option('date_format'); Hook::fire("custom_property_date_format", null, $format); $tmp_date = DateTimeValueLib::dateFromFormatAndString(DATE_MYSQL, $cp_val->getValue()); if (str_starts_with($cp_val->getValue(), EMPTY_DATE)) { $formatted = ""; } else { if (str_ends_with($cp_val->getValue(), "00:00:00")) { $formatted = $tmp_date->format(user_config_option('date_format')); } else { $formatted = $tmp_date->format($format); } } $cp_val->setValue($formatted); } if ($cp->getType() == 'address' && $cp_val instanceof MemberCustomPropertyValue) { $values = str_replace("\\|", "%%_PIPE_%%", $cp_val->getValue()); $exploded = explode("|", $values); foreach ($exploded as &$v) { $v = str_replace("%%_PIPE_%%", "|", $v); $v = str_replace("'", "\\'", $v); } if (count($exploded) > 0) { $address_type = array_var($exploded, 0, ''); $street = array_var($exploded, 1, ''); $city = array_var($exploded, 2, ''); $state = array_var($exploded, 3, ''); $country = array_var($exploded, 4, ''); $zip_code = array_var($exploded, 5, ''); $country_name = CountryCodes::getCountryNameByCode($country); $tmp = array(); if ($street != '') { $tmp[] = $street; } if ($city != '') { $tmp[] = $city; } if ($state != '') { $tmp[] = $state; } if ($zip_code != '') { $tmp[] = $zip_code; } if ($country_name != '') { $tmp[] = $country_name; } $cp_val->setValue(implode(' - ', $tmp)); } } $val_to_show .= ($val_to_show == "" ? "" : ", ") . ($cp_val instanceof MemberCustomPropertyValue ? $cp_val->getValue() : ""); } $val_to_show = html_to_text($val_to_show); return $val_to_show; }
/** * Complete specific milestone * * @access public * @param void * @return null */ function complete() { $milestone = ProjectMilestones::findById(get_id()); if (!$milestone instanceof ProjectMilestone) { flash_error(lang('milestone dnx')); $this->redirectTo('milestone'); } // if if (!$milestone->canChangeStatus(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('milestone')); } // if try { $milestone->setCompletedOn(DateTimeValueLib::now()); $milestone->setCompletedById(logged_user()->getId()); DB::beginWork(); $milestone->save(); ApplicationLogs::createLog($milestone, active_project(), ApplicationLogs::ACTION_CLOSE); DB::commit(); flash_success(lang('success complete milestone', $milestone->getName())); } catch (Exception $e) { DB::rollback(); flash_error(lang('error complete milestone')); } // try $this->redirectToReferer($milestone->getViewUrl()); }
$occup[$event_start->getHour()][1][$posHoriz] = true; } for ($i = $event_start->getHour() + 1; $i < $event_duration->getHour(); $i++) { $occup[$i][0][$posHoriz] = true; $occup[$i][1][$posHoriz] = true; } if ($event_duration->getMinute() > 0) { $occup[$event_duration->getHour()][0][$posHoriz] = true; if ($event_duration->getMinute() > 30) { $occup[$event_duration->getHour()][1][$posHoriz] = true; } } //if ($posHoriz+1 == $evs_same_time) $width = $width - 0.75; $procesados[$hr_start]++; $event_duration->add('s', 1); $ev_duration = DateTimeValueLib::get_time_difference($event_start->getTimestamp(), $event_duration->getTimestamp()); if ($event instanceof ProjectEvent) { $real_start = new DateTimeValue($event->getStart()->getTimestamp() + 3600 * logged_user()->getTimezone()); $real_duration = new DateTimeValue($event->getDuration()->getTimestamp() + 3600 * logged_user()->getTimezone()); } else { if ($event instanceof ProjectTask) { if ($event->getStartDate() instanceof DateTimeValue) { $real_start = new DateTimeValue($event->getStartDate()->getTimestamp() + 3600 * logged_user()->getTimezone()); } else { $real_start = $event_start; } if ($event->getDueDate() instanceof DateTimeValue) { $real_duration = new DateTimeValue($event->getDueDate()->getTimestamp() + 3600 * logged_user()->getTimezone()); } else { $real_duration = $event_duration; }
/** * Empty implementation of static method. Update tag permissions are check by the taggable * object, not tag itself * * @param User $user * @return boolean */ function canEdit(User $user) { $project = $this->getProject(); if (!$project instanceof Project || !$user->isProjectUser($this->getProject())) { return false; } // if $object = $this->getObject(); if ($object instanceof ProjectDataObject) { if ($user->isAdministrator()) { return true; } // if if (!$user->isMemberOfOwnerCompany() && $this->isPrivate()) { return false; // private object } // if $edit_limit = DateTimeValueLib::now(); $edit_limit->advance(180); if ($this->getCreatedById() == $user->getId() && $this->getCreatedOn()->getTimestamp() < $edit_limit->getTimestamp()) { return true; // author withing three minutes } // if } // if return false; }
</td> <td style="padding-right: 10px; width:140px;vertical-align:bottom"> <?php echo label_tag(lang('hours')) ?> </td> <td style="padding-right: 10px; width:140px;vertical-align:bottom"> <?php echo label_tag(lang('minutes')) ?> </td> <td style="padding-right: 10px; width:95%; margin-top: 0px;vertical-align:bottom"> <?php echo label_tag(lang('description')) ?> </td> <td style="padding-left: 10px;text-align:right; vertical-align: middle;"> </td> </tr> <tr> <td style="padding-right: 10px; width:140px;"> <?php echo pick_date_widget2('timeslot[date]', DateTimeValueLib::now(), $genid, 100, false) ?> </td> <td style="padding-right: 10px; width:140px;"> <?php $options = array(); foreach ($users as $user) { $options[] = option_tag($user->getObjectName(), $user->getId(), $selected_user == $user->getId() ? array("selected" => "selected") : null); } echo select_box("timeslot[contact_id]", $options, array('id' => $genid . 'tsUser', 'tabindex' => '150')); ?> </td> <td style="padding-right: 10px; width: 140px;"><?php echo text_field('timeslot[hours]', 0, array('style' => 'width:28px', 'tabindex' => '200', 'id' => $genid . 'tsHours','onkeypress'=>'og.checkEnterPress(event,\''.$genid.'\')')) ?> </td> <td style="padding-right: 10px; width: 140px;">