public function viewAsImage($max_size = 0) { $max_size = intval($max_size); if (!($dimensions = $this->getImageDimensions($max_size))) { log_message("file::viewAsImage({$this->id}) can not find file1 '{$filepath}'", LOG_MESSAGE_MISSING_FILES); return; } $filepath = $dimensions['filepath']; $new_width = $dimensions['new_width']; $new_height = $dimensions['new_height']; $width = $dimensions['width']; $height = $dimensions['height']; $filesize = filesize($filepath); /** * just provide the original file */ if (!$dimensions['downscale']) { header('Content-Length: ' . $filesize); header('Content-Type: ' . $this->mimetype); header("Content-Disposition: inline; filename={$this->org_filename}"); header("Cache-Control: public"); header('Last-Modified: ' . gmdate("D, j M Y G:i:s T", strToClientTime($this->modified))); if ($filesize > 1000000) { readfile_chunked($filepath); } else { readfile($filepath); } return; } /** * rescale with gd */ if (!function_exists('imagecreatetruecolor')) { log_message("file::viewAsImage({$this->id}) gd not installed", LOG_MESSAGE_MISSING_FILES); return; } ### check if cached file exists $md5 = md5(http_build_query(array('filepath' => $filepath, 'new_width' => $new_width, 'new_height' => $new_height))); $cached_filepath = confGet('DIR_IMAGE_CACHE') . "/" . $md5 . ".jpg"; if (file_exists($cached_filepath)) { header('Content-Length: ' . filesize($cached_filepath)); header('Content-Type: ' . $this->mimetype); header("Content-Disposition: inline; filename= {$this->org_filename}"); header("Cache-Control: public"); header('Last-Modified: ' . gmdate("D, j M Y G:i:s T", strToClientTime($this->modified))); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 365) . " GMT"); readfile($cached_filepath); return; } $image_new = NULL; ### downscale if ($this->mimetype == 'image/jpeg' || $this->mimetype == 'image/jpg' || $this->mimetype == 'image/pjpeg') { $image = imagecreatefromjpeg($filepath); } else { if ($this->mimetype == 'image/png' || $this->mimetype == 'image/x-png') { $image = imagecreatefrompng($filepath); } else { if ($this->mimetype == 'image/gif') { $image = imagecreatefromgif($filepath); } else { return NULL; } } } ### Downscale image and stream content header('Content-Type: ' . 'image/jpeg'); header("Cache-Control: public"); ### Tell browser to cache forever, because the file will never change header("Last-Modified: " . gmdate('r', strToClientTime($this->modified))); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 365) . " GMT"); $image_new = imagecreatetruecolor($new_width, $new_height) or die("Cannot Initialize new GD image stream"); if (imagecopyresampled($image_new, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height)) { imagejpeg($image_new); } else { imagejpeg($image); } ### write cached file if ($image_new) { imagejpeg($image_new, $cached_filepath); imagedestroy($image_new); } }
function renderListHtml(&$efforts = NULL) { $this->render_header(); if (!$efforts && $this->no_items_html) { $this->render_tfoot_empty(); } else { $this->render_thead(); $sum = 0.0; $day_last = 0; ### grouping ### if ($this->groupings && $this->active_block_function == 'grouped' && $this->groupings->active_grouping_obj) { $last_group = NULL; $gr = $this->groupings->active_grouping_key; foreach ($efforts as $e) { if ($last_group != $e->{$gr}) { echo '<tr class=group><td colspan=' . count($this->columns) . '>' . $this->groupings->active_grouping_obj->render($e) . '</td></tr>'; $last_group = $e->{$gr}; } $sum += (strToClientTime($e->time_end) - strToClientTime($e->time_start)) / 60 / 60 * 1.0; /** * separate new days with style */ $day = gmdate('z', strToClientTime($e->time_end)) * 1; if ($day != $day_last) { $day_last = $day; $this->render_trow($e, 'isNewDay'); } else { $this->render_trow($e); } } } else { foreach ($efforts as $e) { $sum += (strToClientTime($e->time_end) - strToClientTime($e->time_start)) / 60 / 60 * 1.0; /** * separate new days with style */ $day = gmdate('z', strToClientTime($e->time_end)) * 1; if ($day != $day_last) { $day_last = $day; $this->render_trow($e, 'isNewDay'); } else { $this->render_trow($e); } } } $sum = round($sum, 1); $this->summary = sprintf(__("%s effort(s) with %s hours"), count($efforts), $sum); $this->render_tfoot(); parent::render_blockEnd(); } }
/** * show system information @ingroup pages */ function systemInfo() { global $PH; require_once confGet('DIR_STREBER') . 'render/render_list.inc.php'; $system_info = getSysInfo(); $page = new Page(); $page->tabs['admin'] = array('target' => "index.php?go=systemInfo", 'title' => __('Admin', 'top navigation tab'), 'bg' => "misc"); $page->cur_tab = 'admin'; $page->crumbs[] = new NaviCrumb(array('target_id' => 'systemInfo')); $page->title = __("System information"); $page->type = __("Admin"); #$page->title_minor=get('go'); echo new PageHeader(); echo new PageContentOpen(); $block = new PageBlock(array('title' => __('Overview'), 'id' => 'overview')); $block->render_blockStart(); echo "<div class=text>"; foreach ($system_info as $label => $value) { echo "<div class=labeled><label>{$label}:</label> <span>{$value}</span></div>"; } echo "</div>"; global $auth; echo "<br>"; echo "<h2>Timezone detection</h2>"; echo "<div class=text>"; echo "<ul>"; echo "<li> time-offset for user: "******"sec"; echo "<li> renderDateHtml(): " . renderDateHtml($auth->cur_user->last_login) . ""; echo "<li> original db-string (should be GMT): " . $auth->cur_user->last_login; echo "<li> strToClienttime(): " . strToClientTime($auth->cur_user->last_login); echo "<li> gmdate:(strToClientTime) " . gmdate("H:i:s", strToClientTime($auth->cur_user->last_login)); echo "<li> strToTime(): " . strToTime($auth->cur_user->last_login); echo "<li> date(strToTime): " . date("H:i:s", strToTime($auth->cur_user->last_login)); echo "</ul>"; echo "</div>"; $block->render_blockEnd(); echo new PageContentClose(); echo new PageHtmlEnd(); }
function ajaxUserEfforts() { global $PH; global $auth; require_once confGet('DIR_STREBER') . 'db/class_effort.inc.php'; $efforts = Effort::getAll(array('person' => $auth->cur_user->id, 'effort_time_min' => getGMTString(time() - 7 * 24 * 60 * 60))); $result = array(); foreach ($efforts as $e) { $p = Project::getById($e->project); $task_name = ""; if ($t = Task::getVisibleById($e->task)) { $task_name = $t->name . " — "; } $result[$e->id] = array('start' => strToClientTime($e->time_start), 'duration' => strToClientTime($e->time_end) - strToClientTime($e->time_start), 'id' => $e->id, 'productivity' => $e->productivity, 'color' => $p->color ? "#" . $p->color : "#ff8080", 'title' => $p->name, 'tooltip' => $task_name . $e->name); } echo json_encode($result); }
function renderDateHtml($t) { global $auth; ### this is the visible string ### if (!($str = renderDate($t))) { return "-"; } ### this is for the tooltip ### if (is_string($t)) { $t = strToClientTime($t); } else { global $auth; $time_offset = 0; if (isset($auth->cur_user)) { $time_offset = $auth->cur_user->time_offset; } $t += $time_offset; } ### tooltip ? ### $str_tooltip = ''; if (gmdate('H:i:s', $t) != '00:00:00') { $str_tooltip = gmstrftime(getUserFormatTimestamp(), $t); } if ($str_tooltip) { return "<span class='date' title='{$str_tooltip}'>{$str}</span>"; } else { return $str; } }
public function __toString() { $value_date = "-"; $value_time = "-"; if ($this->value != "0000-00-00 00:00:00" && $this->value != "0000-00-00") { $time = strToClientTime($this->value); /** * if strToClientTime fails, use try mySQL */ if ($time < 0 || $time == false) { $str_array = mysqlDatetime2utc($this->value); $str = $str_array['year'] . "-" . $str_array['mon'] . '-' . $str_array['day'] . " " . $str_array['hour'] . ":" . $str_array['min'] . ":" . $str_array['sec']; $time = strToClientTime($str); } /** * @@@ this format must be parsable by jsCalendar */ if ($time != -1) { $value_date = gmdate("D, d.m.Y", $time); $value_time = gmdate("H:i", $time); } } else { $time = 0; } $label = isset($this->title) ? $this->title : ucwords(str_replace('_', ' ', $this->name)); $tooltip = isset($this->tooltip) ? "title='{$this->tooltip}'" : ucwords($this->name); $field_id = $this->name; $buffer = "<p {$tooltip} " . $this->renderCssClasses() . ">" . "<label>{$label}</label>" . "<input class=inp_date id='{$field_id}_date' name='{$field_id}_date' value='{$value_date}'>" . "<span class=button_calendar id='trigger_{$field_id}_date'>...</span>" . "<input class=inp_time id='{$field_id}_time' name='{$field_id}_time' value='{$value_time}'>" . "<span class=slider_time id='drag_{$field_id}' > </span>" . "</p>" . "<script>" . "DragSlider.init('drag_{$field_id}','{$field_id}_time','time');\r\n Calendar.setup({\r\n inputField : \"{$field_id}_date\", // ID of the input field\r\n ifFormat : \"%a, %d.%m.%Y\", // the date format\r\n button : \"trigger_{$field_id}_date\" // ID of the button\r\n }\r\n );" . "</script>"; return $buffer; }
/** * Submit changes to an effort @ingroup pages */ function effortEditSubmit() { global $PH; global $auth; ### Validate form crc if (!validateFormCrc()) { $PH->abortWarning(__('Invalid checksum for hidden form elements')); } ### get effort #### $id = getOnePassedId('effort'); if ($id == 0) { $effort = new Effort(array('id' => 0)); } else { $effort = Effort::getEditableById($id); if (!$effort) { $PH->abortWarning(__("Could not get effort")); return; } $effort->validateEditRequestTime(); } ### cancel ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $effort->project)); } exit; } ### get project ### $effort->project = get('effort_project'); if (!($project = Project::getVisibleById($effort->project))) { $PH->abortWarning(__("Could not get project of effort")); } if (!$project->isPersonVisibleTeamMember($auth->cur_user)) { $PH->abortWarning("ERROR: Insufficient rights"); } ### get person ### if ($effort->person = get('effort_person')) { if (!($person = Person::getVisibleById($effort->person))) { $PH->abortWarning(__("Could not get person of effort")); } } # retrieve all possible values from post-data # NOTE: # - this could be an security-issue. # - TODO: as some kind of form-edit-behaviour to field-definition foreach ($effort->fields as $f) { $name = $f->name; $f->parseForm($effort); } ### times as duration ### if ($as_duration = get('effort_as_duration')) { $effort->as_duration = $as_duration; ### make sure day of time_end stays the same if date changes... ### if (($time_start = $effort->time_start) && ($time_end = $effort->time_end)) { $effort->time_end = gmdate("Y-m-d", strToClientTime($time_end)) . " " . gmdate("H:i:s", strToClientTime($time_end)); $effort->time_start = gmdate("Y-m-d", strToClientTime($time_end)) . " " . gmdate("00:00:00", strToClientTime($time_end)); } else { trigger_error("Getting time_start and time_end failed", E_USER_WARNING); } } ### pub level ### if ($pub_level = get('effort_pub_level')) { ### not a new effort ### if ($effort->id) { if ($pub_level > $effort->getValidUserSetPublicLevels()) { $PH->abortWarning('invalid data', ERROR_RIGHTS); } } #else { # #@@@ check for person create rights #} $effort->pub_level = $pub_level; } ## effort status ## if ($effort_status = get('effort_status')) { $effort->status = $effort_status; } if ($effort_billing = get('effort_billing')) { $effort->billing = intval($effort_billing); } if ($effort_productivity = get('effort_productivity')) { $effort->productivity = intval($effort_productivity); } ### link to task ### $task_id = get('effort_task'); if (!is_null($task_id)) { if ($task_id == 0) { $effort->task = 0; } else { if ($task = Task::getVisibleById($task_id)) { $effort->task = $task->id; } } } ### go back to from if validation fails ### $failure = false; if (!$effort->name) { $failure = true; new FeedbackWarning(__("Name required")); } if (strToGMTime($effort->time_end) - strToGMTime($effort->time_start) < 0) { $failure = true; new FeedbackWarning(__("Cannot start before end.")); } ### validation of the Datetime fields### if (!$as_duration) { if (strToGMTime($effort->time_start) == 0) { $failure = true; $name = $effort->fields['time_start']->name; $field_id = $effort->_type . '_' . $name; $value_time = get($field_id . '_time'); new FeedbackWarning(sprintf(__("<b>%s</b> is not a valid value for start time."), $value_time)); $effort->time_start = getGMTString(); } if (strToGMTime($effort->time_end) == 0) { $failure = true; $name = $effort->fields['time_end']->name; $field_id = $effort->_type . '_' . $name; $value_time = get($field_id . '_time'); new FeedbackWarning(sprintf(__("<b>%s</b> is not a valid value for end time."), $value_time)); $effort->time_end = getGMTString(); } } else { ##As duration if (strToGMTime($effort->time_end) == 0) { $failure = true; $name = $effort->fields['time_end']->name; $field_id = $effort->_type . '_' . $name; $value_time = get($field_id . '_time'); new FeedbackWarning(sprintf(__("<b>%s</b> is not a valid value for hours."), $value_time)); $effort->time_end = gmdate("Y-m-d", time()) . " 00:00:00"; } } if ($failure) { $PH->show('effortEdit', NULL, $effort); exit; } ### write to db ### if ($effort->id == 0) { $effort->insert(); } else { $effort->update(); } ### display taskView #### if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $effort->project)); } }