/** * Extended substr function. If it finds mbstring extension it will use, else * it will use old substr() function * * @param string $string String that need to be fixed * @param integer $start Start extracting from * @param integer $length Extract number of characters * @return string */ function substr_utf($string, $start = 0, $length = null) { $start = (int) $start >= 0 ? (int) $start : 0; if (is_null($length)) { $length = strlen_utf($string) - $start; } return substr($string, $start, $length); }
/** * Extended substr function. If it finds mbstring extension it will use, else * it will use old substr() function * * @param string $string * @param integer $start * @param integer $length * @return string */ function substr_utf($string, $start = 0, $length = null) { $start = (int) $start >= 0 ? (int) $start : 0; if (is_null($length)) { $lenght = strlen_utf($string) - $start; } // if return CAN_USE_MBSTRING ? mb_substr($string, $start, $length, 'UTF-8') : substr($string, $start, $length); }
/** * Return the first $len - 3 characters of the comment's text followed by "..." * * @param unknown_type $len */ function getPreviewText($len = 30) { if ($len <= 3) return "..."; $text = $this->getText(); if (strlen_utf($text) > $len) { return substr_utf($text, 0, $len - 3) . "..."; } else { return $text; } }
/** * Extended substr function. If it finds mbstring extension it will use, else * it will use old substr() function * * @access public * @param string $string String that need to be fixed * @param integer $start Start extracting from * @param integer $length Extract number of characters * @return string */ function substr_utf($string, $start = 0, $length = null) { $start = (int) $start >= 0 ? (int) $start : 0; if (is_null($length)) { $length = strlen_utf($string) - $start; } // if if (function_exists('mb_substr')) { return mb_substr($string, $start, $length); } else { return substr($string, $start, $length); } // if }
/** * Return object name * * @access public * @param void * @return string */ function getObjectName($charLimit = 0) { $name = $this->getTitle(); if (!$name) { $name = $this->getText(); } if ($charLimit > 0 && strlen_utf($name) > $charLimit) { return substr_utf($name, 0, $charLimit) . '...'; } else { return $name; } }
} else { $real_duration = $event_duration; } } } $pre_tf = $real_start->getDay() == $real_duration->getDay() ? '' : 'D j, '; $ev_hour_text = format_date($real_start, $pre_tf . $timeformat, 0) . " - " . format_date($real_duration, $pre_tf . $timeformat, 0); $assigned = ""; if ($event instanceof ProjectTask && $event->getAssignedToContactId() > 0) { $assigned = "<br>" . lang('assigned to') . ': ' . $event->getAssignedToName(); $tipBody = purify_html($event->getText()); } else { $tipBody = $ev_hour_text . $assigned . (trim(clean($event->getDescription())) != '' ? '<br><br>' . clean($event->getDescription()) : ''); $tipBody = str_replace(array("\r", "\n"), array(' ', '<br>'), $tipBody); } if (strlen_utf($tipBody) > 200) { $tipBody = substr_utf($tipBody, 0, strpos($tipBody, ' ', 200)) . ' ...'; } ?> <script> if (<?php echo $top; ?> < scroll_to || scroll_to == -1) { scroll_to = <?php echo $top; ?> ; } addTip('d_ev_div_' + <?php echo $event->getId();
function get_conversation_info() { $email = MailContents::findById(array_var($_GET, 'id')); if (!$email instanceof MailContent) { flash_error(lang('email dnx')); ajx_current("empty"); return; } $info = array(); $mails = MailContents::getMailsFromConversation($email); foreach ($mails as $mail) { $text = $mail->getBodyPlain(); if (strlen_utf($text) > 80) { $text = substr_utf($text, 0, 80) . "..."; } $state = $mail->getState(); $show_user_icon = false; if ($state == 1 || $state == 3 || $state == 5) { if ($mail->getCreatedById() == logged_user()->getId()) { $from = lang('you'); } else { $from = $mail->getCreatedByDisplayName(); } $show_user_icon = true; } else { $from = $mail->getFrom(); } $info[] = array('id' => $mail->getId(), 'date' => $mail->getReceivedDate() instanceof DateTimeValue ? $mail->getReceivedDate()->isToday() ? format_time($mail->getReceivedDate()) : format_datetime($mail->getReceivedDate()) : lang('n/a'), 'has_att' => $mail->getHasAttachments(), 'text' => htmlentities($text), 'read' => $mail->getIsRead(logged_user()->getId()), 'from_name' => $state == 1 || $state == 3 || $state == 5 ? lang('you') : $mail->getFromName(), 'from' => $from, 'show_ico' => $show_user_icon); } tpl_assign('source_email_id', array_var($_GET, 'id')); tpl_assign('emails_info', $info); $this->setLayout("html"); $this->setTemplate("llo_email_conversation"); ajx_current("empty"); }
function export_to_csv_file() { $ids = array_var($_REQUEST, 'ids'); $idsall = array_var($_REQUEST, 'allIds'); $export_all = array_var($_REQUEST, 'export_all'); $this->setTemplate('csv_export'); $type = array_var($_REQUEST, 'type', array_var($_SESSION, 'import_type', 'contact')); //type of import (contact - company) tpl_assign('import_type', $type); if (!isset($_SESSION['import_type']) || $type != $_SESSION['import_type'] && $type != '') { $_SESSION['import_type'] = $type; } $delimiter = array_var($_REQUEST, 'delimiter', ','); if ($delimiter == '') { $delimiter = ','; } $checked_fields = $type == 'contact' ? array_var($_REQUEST, 'check_contact') : array_var($_REQUEST, 'check_company'); if (is_array($checked_fields) && ($ids || $idsall || $export_all)) { $titles = ''; $imp_type = array_var($_SESSION, 'import_type', 'contact'); if ($imp_type == 'contact') { $field_names = Contacts::getContactFieldNames(); foreach ($checked_fields as $k => $v) { if (isset($field_names["contact[{$k}]"]) && $v == 'checked') { $titles .= $field_names["contact[{$k}]"] . $delimiter; } } $titles = substr_utf($titles, 0, strlen_utf($titles) - 1) . "\n"; } else { $field_names = Contacts::getCompanyFieldNames(); foreach ($checked_fields as $k => $v) { if (isset($field_names["company[{$k}]"]) && $v == 'checked') { $titles .= $field_names["company[{$k}]"] . $delimiter; } } $titles = substr_utf($titles, 0, strlen_utf($titles) - 1) . "\n"; } // export the same type of contact objects that are enabled in the contacts tab. $extra_conditions = ""; if (array_var($_SESSION, 'import_type', 'contact') == 'contact') { $extra_conditions = ' `is_company` = 0 '; if (!user_config_option("viewContactsChecked")) { $extra_conditions .= ' AND `user_type` != 0 '; } if (!user_config_option("viewUsersChecked")) { $extra_conditions .= ' AND `user_type` < 1 '; } } // -- $filename = rand() . '.tmp'; $handle = fopen(ROOT . '/tmp/' . $filename, 'wb'); fwrite($handle, $titles); $conditions = $extra_conditions; $ids_sql = ""; if (!$export_all) { $ids_sql = $ids ? " AND id IN (" . $ids . ") " : ""; } $members = active_context_members(false); $context_condition = $this->getActiveContextConditions(); if (array_var($_SESSION, 'import_type', 'contact') == 'contact') { $conditions .= " AND `archived_by_id` = 0 "; $conditions .= $ids_sql; $conditions .= $context_condition; $contacts = Contacts::instance()->getAllowedContacts($conditions); foreach ($contacts as $contact) { fwrite($handle, $this->build_csv_from_contact($contact, $checked_fields, $delimiter) . "\n"); } } else { $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND {$conditions}" : ""); $conditions .= $ids_sql; $conditions .= $context_condition; $companies = Contacts::getVisibleCompanies(logged_user(), $conditions); foreach ($companies as $company) { fwrite($handle, $this->build_csv_from_company($company, $checked_fields, $delimiter) . "\n"); } } fclose($handle); $_SESSION['contact_export_filename'] = $filename; flash_success($imp_type == 'contact' ? lang('success export contacts') : lang('success export companies')); } }
/** * Return object name * * @access public * @param void * @return string */ function getObjectName() { $return = substr_utf($this->getText(), 0, 50); return strlen_utf($this->getText()) > 50 ? $return . '...' : $return; }
/** * Return shortened description * * @access public * @param void * @return string */ function getShortDescription() { $return = substr_utf($this->getDescription(), 0, 50); return strlen_utf($this->getDescription()) > 50 ? $return . '...' : $return; }
/** * Return comment that need to be stored in activity log * * By default this function will extract data from body field (if present). * If you need a bit different behavior override this function in subclasses * * @param void * @return string */ function getActivityLogComment() { $body = strip_tags($this->getBody()); if ($body) { $beginning = substr_utf($body, 0, 120); if (strlen_utf($beginning) < strlen_utf($body)) { $beginning .= '...'; } // if return $beginning; } // if return null; }
/** * Return object name * * @access public * @param void * @return string */ function getObjectName() { $name = $this->getText(); $len = strlen_utf($name); $i = strpos($name, "\n"); if ($i !== false) { $name = substr_utf($name, 0, $i - 1); } $return = substr_utf($name, 0, 50); return $len > 50 ? $return . '...' : $return; }
/** * Prepare HTML before saving it into database * * @param string $value * @param boolean $purify * @return string */ function prepare_html($value, $purify = false) { require_once ANGIE_PATH . '/classes/htmlpurifier/init.php'; $value = trim($value); if ($value != '') { // Remove brs from the end of the string if (str_ends_with($value, '<br /><br />')) { $value = substr_utf($value, 0, strlen_utf($value) - 12); } // if if ($purify) { $value = purify_html($value); } // if // Clean up Microsoft Office paste: // <p> <!-- /* Font Definitions */--> </p> if (str_starts_with($value, '<p> <!-- /* Font Definitions */')) { $value = preg_replace('/(<p>)[\\s]+(\\<\\!--)[\\s]+(\\/\\*)[\\s]+(Font)[\\s]+(Definitions)[\\s]+(\\*\\/)(.*)(--\\>\\;)[\\s]+(<\\/p>)/i', '', $value); } // if return str_replace(array('<br>', '<br/>', '<br />'), array("\n", "\n", "\n"), $value); } // if return ''; }
private function minWordLength($str) { $min = null ; foreach ( explode(" ", $str) as $word ){ if ( $len = strlen_utf(trim($word)) ){ if (is_null($min) || $len < $min) { $min = $len ; } } } return $min ; }
$tip_pre = 'end_'; } else { $tip_title = lang('start of task'); $img_url = image_url('/16x16/task_start.png'); $tip_pre = 'st_'; } $tip_pre .= gen_id()."_"; $count++; if ($count <= $max_events_to_show){ $color = 'B1BFAC'; $subject = clean($task->getObjectName()).'- <span class="italic">'.lang('task').'</span>'; $cal_text = clean($task->getObjectName()); $tip_text = str_replace("\r", '', lang('assigned to') .': '. clean($task->getAssignedToName()) . (trim($task->getText()) == '' ? '' : '<br><br>'. $task->getText())); $tip_text = purify_html(str_replace("\n", '<br>', $tip_text)); if (strlen_utf($tip_text) > 200) $tip_text = substr_utf($tip_text, 0, strpos($tip_text, ' ', 200)) . ' ...'; ?> <div id="m_ta_div_<?php echo $tip_pre.$task->getId()?>" class="<?php echo "og-wsname-color-$ws_color" ?>" style="height:20px;margin: 1px;padding-left:1px;padding-bottom:0px;border-radius:4px;border: 1px solid;border-color:<?php echo $border_color ?>;<?php echo $extra_style ?>"> <a href='<?php echo $task->getViewUrl()?>' class='internalLink nobr' onclick="og.disableEventPropagation(event);return true;" style="border-width:0px"> <img src="<?php echo $img_url ?>" style="vertical-align: middle;"> <span><?php echo $cal_text ?></span> </a> </div> <script> addTip('m_ta_div_<?php echo $tip_pre.$task->getId() ?>', '<span class="italic">' + '<?php echo $tip_title ?>' + '</span> - ' + <?php echo json_encode(clean($task->getTitle()))?>, <?php echo json_encode(trim($tip_text) != '' ? trim($tip_text) : '');?>); <?php if (!logged_user()->isGuest()) { ?> og.createMonthlyViewDrag('m_ta_div_<?php echo $tip_pre.$task->getId() ?>', '<?php echo $task->getId()?>', false, 'task'); // Drag <?php } ?> </script> <?php }//if count
$show_help_option = user_config_option('show_context_help'); if ($show_help_option == 'always' || ($show_help_option == 'until_close' && user_config_option('show_active_tasks_widget_context_help', true, logged_user()->getId()))) { render_context_help($this, 'chelp active tasks widget', 'active_tasks_widget'); } ?> <div style="padding:10px"> <table id="dashTableTIP" style="width:100%;"> <?php $c = 0; foreach ($tasks_in_progress as $task) { $stCount = $task->countAllSubTasks(); $c++; $text = $task->getText(); if ($text != '') $text = ": " . $text; if(strlen_utf($text)>100) $text = substr_utf($text,0,100) . " ..."; $text = clean($text); ?> <tr class="<?php echo $c % 2 == 1? '':'dashAltRow'?>"><td><div class="db-ico ico-task"> ></div></td><td style="padding-left:5px;padding-bottom:2px"> <?php $dws = $task->getWorkspaces(logged_user()->getWorkspacesQuery()); $projectLinks = array(); foreach ($dws as $ws) { $projectLinks[] = $ws->getId(); } echo '<span class="project-replace">' . implode(',',$projectLinks) . '</span>';?> <a class='internalLink' href='<?php echo $task->getViewUrl() ?>'><?php echo clean($task->getTitle())?><?php echo $text ?></a></td> <?php /*<td align="right"><?php $timeslot = Timeslots::getOpenTimeslotByObject($task,logged_user()); if ($timeslot) { if (!$timeslot->isPaused()) {?> <div id="<?php echo $genid . $task->getId() ?>timespan"></div>
"></span> <script> var crumbHtml = <?php echo $crumbJs; ?> ; $("#object_crumb_<?php echo $object->getId(); ?> ").html(crumbHtml); </script> <?php if ($object instanceof ProjectTask) { $text = strlen_utf($object->getText()) > 100 ? substr_utf(html_to_text($object->getText()), 0, 100) . "..." : strip_tags($object->getText()); $text = remove_scripts($text); if (strlen_utf($text) > 0) { ?> - <span class="desc nobr"><?php echo $text; ?> </span> <?php } ?> <?php } ?> </div> </td> </tr>
/** * Return begining of the string * * @param string $string * @param integer $lenght * @param string $etc * @return string */ function str_excerpt($string, $lenght = 100, $etc = '...') { return strlen_utf($string) <= $lenght + 3 ? $string : substr_utf($string, 0, $lenght) . $etc; }
} $pre_tf = $real_start->getDay() == $real_duration->getDay() ? '' : 'D j, '; $ev_hour_text = (!$event->isRepetitive() && $real_start->getDay() != $event_start->getDay()) ? "... ".format_date($real_duration, $timeformat, 0) : format_date($real_start, $timeformat, 0); $assigned = ""; if ($event instanceof ProjectTask && $event->getAssignedToContactId() > 0) { $assigned = "<br>" . lang('assigned to') .': '. $event->getAssignedToName(); $task_desc = purify_html($event->getText()); $tipBody = lang('assigned to') .': '. clean($event->getAssignedToName()) . (trim(clean($event->getText())) != '' ? '<br><br>' . trim($task_desc) : ''); } else { $tipBody = format_date($real_start, $pre_tf.$timeformat, 0) .' - '. format_date($real_duration, $pre_tf.$timeformat, 0) . $assigned . (trim(clean($event->getDescription())) != '' ? '<br><br>' . clean($event->getDescription()) : ''); $tipBody = str_replace("\r", '', $tipBody); $tipBody = str_replace("\n", '<br>', $tipBody); } if (strlen_utf($tipBody) > 200) $tipBody = substr_utf($tipBody, 0, strpos($tipBody, ' ', 200)) . ' ...'; $ev_duration = DateTimeValueLib::get_time_difference($event_start->getTimestamp(), $event_duration->getTimestamp()); $id_suffix = "_$day_of_week"; ?> <script> if (<?php echo $top; ?> < scroll_to || scroll_to == -1) { scroll_to = <?php echo $top;?>; } addTip('w_ev_div_' + '<?php echo $event->getId() . $id_suffix ?>', <?php echo json_encode(clean($event->getObjectName())) ?>, <?php echo json_encode($tipBody);?>); </script> <?php $bold = "bold"; if ($event instanceof Contact || $event->getIsRead(logged_user()->getId())){ $bold = "normal"; }
/** * Reset users password * * @param void * @return null */ function reset_password() { $user_id = $this->request->getId('user_id'); $code = trim($this->request->get('code')); if (empty($user_id) || empty($code)) { $this->httpError(HTTP_ERR_INVALID_PROPERTIES); } // if $user = null; if ($user_id) { $user = Users::findById($user_id); } // if // Valid user and key if (!instance_of($user, 'User')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if ($user->getPasswordResetKey() != $code) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if // Not expired $reset_on = $user->getPasswordResetOn(); if (instance_of($reset_on, 'DateTimeValue')) { if ($reset_on->getTimestamp() + 172800 < time()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if } else { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $reset_data = $this->request->post('reset'); $this->smarty->assign(array('reset_data' => $reset_data, 'user' => $user)); if ($this->request->isSubmitted()) { $password = array_var($reset_data, 'password'); $password_a = array_var($reset_data, 'password_a'); $errors = new ValidationErrors(); if (strlen_utf($password) < 3) { $errors->addError(lang('Minimal password length is 3 characters'), 'password'); } // if if ($password != $password_a) { $errors->addError(lang('Passwords do not match'), 'passwords'); } // if if ($errors->hasErrors()) { $this->smarty->assign('errors', $errors); $this->render(); } // if $user->setPassword($password); $user->setPasswordResetKey(null); $user->setPasswordResetOn(null); $save = $user->save(); if ($save && !is_error($save)) { $this->authentication->provider->logUserIn($user); flash_success('Welcome back :name', array('name' => $user->getDisplayName())); $this->redirectTo('dashboard'); } else { $this->smarty->assign('errors', $errors); } // if } // if }
/** * Prepare SQL (replace ? with data from $arguments array) * * @param string $sql SQL that need to be prepared * @param array $arguments Array of SQL arguments... * @return string */ function prepareSQL($sql, $arguments = null) { if (is_foreachable($arguments)) { $offset = 0; foreach ($arguments as $argument) { $question_mark_pos = strpos_utf($sql, '?', $offset); if ($question_mark_pos !== false) { $escaped = $this->escapeString($argument); $escaped_len = strlen_utf($escaped); $sql = substr_utf($sql, 0, $question_mark_pos) . $escaped . substr_utf($sql, $question_mark_pos + 1, strlen_utf($sql)); $offset = $question_mark_pos + $escaped_len; } // if } // foreach } // if return $sql; }
function safe_name($text, $use_visual_mode = false) { if (!$text) { return ''; } $text = strtolower_utf($text); $translation_table = array('ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n', 'ō' => 'o', 'š' => 's', 'ū' => 'u', 'ž' => 'z', 'а' => 'a', 'б' => 'b', 'в' => $use_visual_mode ? 'b' : 'v', 'г' => 'g', 'д' => $use_visual_mode ? 'g' : 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'z', 'з' => $use_visual_mode ? '3' : 'z', 'и' => $use_visual_mode ? 'u' : 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => $use_visual_mode ? 'h' : 'n', 'о' => 'o', 'п' => 'p', 'р' => $use_visual_mode ? 'p' : 'r', 'с' => $use_visual_mode ? 'c' : 's', 'т' => 't', 'у' => $use_visual_mode ? 'y' : 'u', 'ф' => 'f', 'х' => $use_visual_mode ? 'x' : 'h', 'ц' => 'c', 'ч' => 'c', 'ш' => 's', 'щ' => 's', 'ъ' => '', 'ы' => 'i', 'ь' => '', 'э' => 'e', 'ю' => 'u', 'я' => 'j', 'ґ' => 'g', 'і' => 'i', 'ї' => 'i', 'є' => 'e'); $text = strtr($text, $translation_table); $allowed_chars = 'abcdefghijklmnopqrstuvwxyz01234567890_'; $out = ''; for ($i = 0; $i < strlen_utf($text); $i++) { $char = substr_utf($text, $i, 1); if (strlen($char) != 1) { $out .= '_'; } else { if (strpos($allowed_chars, $char) !== FALSE) { $out .= $char; } else { $out .= '_'; } } } $out = trim($out, '_'); $out = preg_replace('/__+/u', '_', $out); $out = preg_replace('/--+/u', '-', $out); if ($out == '') { $out = '_'; } return $out; }
/** * split $content into bayesian relevant words (tokens) * * @param string $content * @return array */ function getTokens(&$content) { // if there is no content, there will be no tokens if (!$content) { return array(); } // if $maximum_token_length = BAYESIAN_MAXIMUM_TOKEN_LENGTH; $minimum_token_length = BAYESIAN_MINIMUM_TOKEN_LENGTH; // container for all tokens $all_tokens = array(); // we need lowercased content $content = strtolower($content); // list of matches that needs to be preserved (add criterias as much you need) $preserve_matches = array(array('expression' => '/([A-Za-z0-9\\_\\-\\.\\+]+\\@[A-Za-z0-9_\\-\\.]+)/', 'result_index' => 0, 'data' => 'email_address'), array('expression' => '/(\\d+\\.\\d+\\.\\d+.\\d+)/', 'result_index' => 0, 'data' => 'ip_address'), array('expression' => '/http\\:\\/\\/([A-Za-z0-9\\_\\-\\.\\/]+)/', 'result_index' => 0, 'data' => 'url')); $ignored_hosts = array('gmail', 'google', 'hotmail', 'yahoo', 'mail', 'microsoft'); // extract matches from content, considering ignored hosts if (is_foreachable($preserve_matches)) { foreach ($preserve_matches as $preserve_match) { preg_match_all(array_var($preserve_match, 'expression'), $content, $matches); if (is_foreachable($matches) && isset($matches[array_var($preserve_match, 'result_index')])) { $matches = $matches[array_var($preserve_match, 'result_index')]; $content = str_replace($matches, ' ', $content); switch (array_var($preserve_match, 'data')) { case 'email_address': // we can't use public emails for consideration for ($x = 0; $x < count($matches); $x++) { $is_ignored = false; foreach ($ignored_hosts as $ignored_host) { if (strpos_utf($matches[$x], '@' . $ignored_host . '.')) { $is_ignored = true; continue; } // if } // if if ($is_ignored) { unset($matches[$x]); } // if } // for break; case 'url': // we can't use public emails for consideration for ($x = 0; $x < count($matches); $x++) { $parse_url = parse_url($matches[$x]); $matches[$x] = array_var($parse_url, 'host'); $is_ignored = false; foreach ($ignored_hosts as $ignored_host) { if (strpos_utf($matches[$x], $ignored_host . '.')) { $is_ignored = true; continue; } // if } // if if ($is_ignored) { unset($matches[$x]); } // if } // for break; } $all_tokens = array_merge($all_tokens, $matches); } // if } // foreach } // if // now when we have extracted valuable data, we need to strip rest of the content of html tags $content = strip_tags(trim($content)); // break content string by any whitespace character, and choose words (tokens) that fits our needs // length must be in scope $maximum_token_length - $minimum_token_length and it cannot be empty string or some kind of numeric (integer or string) // $possible_tokens = preg_split( "/[\\s,.:;\"!?\\\`]+/", $content); // obsolete (it's better to treat all printable signs as part of token $possible_tokens = preg_split("/[\\s]+/", $content); if (is_foreachable($possible_tokens)) { foreach ($possible_tokens as $possible_token) { $possible_token = trim($possible_token); $token_length = strlen_utf($possible_token); if ($token_length > 0 && $token_length >= $minimum_token_length && $token_length <= $maximum_token_length && !is_numeric($possible_token) && !in_array($possible_token, $all_tokens)) { $all_tokens[] = $possible_token; } // if } // foreach } // if return $all_tokens; }
$tip_pre = 'st_'; } } $count++; if ($count <= 3) { $cal_text = clean($task->getTitle()); $cal_text = mb_strlen($cal_text) < $to_show_len ? $cal_text : mb_substr($cal_text, 0, $to_show_len - 3) . "..."; $output .= '<div class="event_block">'; $output .= "<span id='o_ta_div_{$tip_pre}" . $task->getId() . "'>"; $output .= "<a class=\"internalLink link-ico {$ico}\" style='vertical-align:bottom;' href='" . $task->getViewUrl() . "' onclick=\"og.disableEventPropagation(event);\" >"; $output .= $cal_text . "</a>"; $output .= '</span>'; $output .= "</div>"; $tip_text = str_replace("\r", '', lang('assigned to') . ': ' . clean($task->getAssignedToName()) . (trim(clean($task->getText())) == '' ? '' : '<br><br>' . clean($task->getText()))); $tip_text = str_replace("\n", '<br>', $tip_text); if (strlen_utf($tip_text) > 200) { $tip_text = substr_utf($tip_text, 0, strpos($tip_text, ' ', 200)) . ' ...'; } ?> <script> addTip('o_ta_div_<?php echo $tip_pre; ?> ' + <?php echo $task->getId(); ?> , '<i>' + '<?php echo $tip_title; ?> ' + '</i> - ' + <?php echo json_encode(clean($task->getTitle()));
} $read_style = ""; if (!$info->getIsRead(logged_user()->getId())) { $read_style = "font-weight: bold;"; $unread++; } $conversation_block .= '<td style="width:20px;' . $read_style . '">'; if ($info->getHasAttachments()) { $conversation_block .= '<div class="db-ico ico-attachment"></div>'; } $conversation_block .= '<td style="width:20px;' . $read_style . '">'; if ($show_user_icon) { $conversation_block .= '<div class="db-ico ico-user"></div>'; } $info_text = $info->getTextBody(); if (strlen_utf($info_text) > 90) { $info_text = substr_utf($info_text, 0, 90) . "..."; } $view_url = get_url('mail', 'view', array('id' => $info->getId(), 'replace' => 1)); $conversation_block .= '<td>'; $conversation_block .= ' <a style="' . $read_style . '" class="internalLink" href="' . $view_url . '" onclick="og.openLink(\'' . $view_url . '\');return false;" title="' . $info->getFrom() . '">'; $conversation_block .= $from; if (!$is_current) { $conversation_block .= ' </a><span class="desc">- ' . $info_text . '</span></td>'; } $info_date = $info->getReceivedDate() instanceof DateTimeValue ? $info->getReceivedDate()->isToday() ? format_time($info->getReceivedDate()) : format_datetime($info->getReceivedDate()) : lang('n/a'); $conversation_block .= '</td><td style="text-align:right;padding-right:3px"><span class="desc">' . lang('date') . ': </span>' . $info_date . '</td>'; } //foreach $conversation_block .= '</table>'; $conversation_block .= '</div>';
function export_to_csv_file() { $this->setTemplate('csv_export'); $ids = array_var($_GET, 'ids'); $type = array_var($_GET, 'type', array_var($_SESSION, 'import_type', 'contact')); //type of import (contact - company) tpl_assign('import_type', $type); if (!isset($_SESSION['import_type']) || ($type != $_SESSION['import_type'] && $type != '')){ $_SESSION['import_type'] = $type; } $checked_fields = ($type == 'contact') ? array_var($_POST, 'check_contact') : array_var($_POST, 'check_company'); if (is_array($checked_fields)) { $titles = ''; $imp_type = array_var($_SESSION, 'import_type', 'contact'); if ($imp_type == 'contact') { $field_names = Contacts::getContactFieldNames(); foreach($checked_fields as $k => $v) { if (isset($field_names["contact[$k]"]) && $v == 'checked') $titles .= $field_names["contact[$k]"] . ','; } $titles = substr_utf($titles, 0, strlen_utf($titles)-1) . "\n"; }else{ $field_names = Contacts::getCompanyFieldNames(); foreach($checked_fields as $k => $v) { if (isset($field_names["company[$k]"]) && $v == 'checked') $titles .= $field_names["company[$k]"] . ','; } $titles = substr_utf($titles, 0, strlen_utf($titles)-1) . "\n"; } $filename = rand().'.tmp'; $handle = fopen(ROOT.'/tmp/'.$filename, 'wb'); fwrite($handle, $titles); $conditions = ''; $ids_sql = ($ids)? " AND id IN (".$ids.") " : ""; if (array_var($_SESSION, 'import_type', 'contact') == 'contact') { $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND $conditions" : ""); $conditions .= $ids_sql; $contacts = Contacts::instance()->getAllowedContacts($conditions); foreach ($contacts as $contact) { fwrite($handle, $this->build_csv_from_contact($contact, $checked_fields) . "\n"); } }else{ $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND $conditions" : ""); $conditions .=$ids_sql; $companies = Contacts::getVisibleCompanies(logged_user(), $conditions); foreach ($companies as $company) { fwrite($handle, $this->build_csv_from_company($company, $checked_fields) . "\n"); } } fclose($handle); $_SESSION['contact_export_filename'] = $filename; flash_success(($imp_type == 'contact' ? lang('success export contacts') : lang('success export companies'))); } else { unset($_SESSION['contact_export_filename']); return; } }
/** * Alternative imap_utf8 function * * @param string $something_to_decode */ function imap_utf8_alt($something_to_decode) { if (!trim($something_to_decode)) { return null; } // if // if function exists we will try to use it in order to decode subject, otherwise we use buggy imap_utf8 if (function_exists('imap_mime_header_decode')) { $decoded = imap_mime_header_decode($something_to_decode); if (is_foreachable($decoded)) { $decoded_string = ''; foreach ($decoded as $element) { if (strtoupper($element->charset) != 'UTF-8' && strtoupper($element->charset) != 'DEFAULT') { $decoded_string .= convert_to_utf8($element->text, $element->charset); } else { $decoded_string .= $element->text; } // if } // foreach $decoded_string = trim($decoded_string); if ($decoded_string) { return $decoded_string; } // if } // if } // if $decoded_string = trim(imap_utf8($something_to_decode)); if (strlen_utf($decoded_string) > 0) { return $decoded_string; } // if return $something_to_decode; }
if (!$info->getIsRead(logged_user()->getId()) ) { $read_style = "font-weight: bold;"; $unread++; } $conversation_block .= '<td style="width:20px;'.$read_style.'">'; if ($info->getHasAttachments()) { $conversation_block .= '<div class="db-ico ico-attachment"></div>'; } $conversation_block .= '<td style="width:20px;'.$read_style.'">'; if ($show_user_icon) { $conversation_block .= '<div class="db-ico ico-user"></div>'; } $info_text = $info->getTextBody(); if (strlen_utf($info_text) > 90) $info_text = substr_utf($info_text, 0, 90) . "..."; $view_url = get_url('mail', 'view', array('id' => $info->getId(), 'replace' => 1)); $conversation_block .= '<td>'; $conversation_block .= ' <a style="'.$read_style.'" class="internalLink" href="'.$view_url.'" onclick="og.openLink(\''.$view_url.'\');return false;" title="'.$info->getFrom().'">'; $conversation_block .= $from; if (!$is_current) $conversation_block .= ' </a><span class="desc">- '.$info_text.'</span></td>'; $info_date = $info->getReceivedDate() instanceof DateTimeValue ? ($info->getReceivedDate()->isToday() ? format_time($info->getReceivedDate()) : format_datetime($info->getReceivedDate())) : lang('n/a'); $conversation_block .= '</td><td style="text-align:right;padding-right:3px"><span class="desc">'. lang('date').': </span>'. $info_date .'</td>'; } //foreach $conversation_block .= '</table>'; $conversation_block .= '</div>'; } else { $conversation_block = '';
function export_to_csv_file() { $this->setTemplate('csv_export'); $type = array_var($_GET, 'type', array_var($_SESSION, 'import_type', 'contact')); //type of import (contact - company) tpl_assign('import_type', $type); if (!isset($_SESSION['import_type']) || $type != $_SESSION['import_type'] && $type != '') { $_SESSION['import_type'] = $type; } if ($type == 'contact') { $checked_fields = array_var($_POST, 'check_contact'); } else { $checked_fields = array_var($_POST, 'check_company'); } if (is_array($checked_fields)) { $titles = ''; $imp_type = array_var($_SESSION, 'import_type', 'contact'); if ($imp_type == 'contact') { $field_names = Contacts::getContactFieldNames(); foreach ($checked_fields as $k => $v) { if (isset($field_names["contact[{$k}]"]) && $v == 'checked') { $titles .= $field_names["contact[{$k}]"] . ','; } } $titles = substr_utf($titles, 0, strlen_utf($titles) - 1) . "\n"; } else { $field_names = Companies::getCompanyFieldNames(); foreach ($checked_fields as $k => $v) { if (isset($field_names["company[{$k}]"]) && $v == 'checked') { $titles .= $field_names["company[{$k}]"] . ','; } } $titles = substr_utf($titles, 0, strlen_utf($titles) - 1) . "\n"; } $filename = rand() . '.tmp'; $handle = fopen(ROOT . '/tmp/' . $filename, 'wb'); fwrite($handle, $titles); $project = active_project(); if ($project instanceof Project) { $pids = $project->getAllSubWorkspacesQuery(true); } $wsConditions = null; $tag_str = null; $tag = array_var($_GET, 'active_tag'); if (array_var($_SESSION, 'import_type', 'contact') == 'contact') { if (isset($pids)) { $wsConditions = Contacts::getWorkspaceString($pids); } if (isset($tag) && $tag && $tag != '') { $tag_str = " EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` = " . DB::escape($tag) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = 'Contacts') "; } $conditions = $wsConditions ? $wsConditions . ($tag_str ? " AND {$tag_str}" : '') : $tag_str; $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND {$conditions}" : ""); $contacts = Contacts::instance()->getAllowedContacts($conditions); foreach ($contacts as $contact) { fwrite($handle, $this->build_csv_from_contact($contact, $checked_fields) . "\n"); } } else { if (isset($pids)) { $wsConditions = Companies::getWorkspaceString($pids); } if (isset($tag) && $tag && $tag != '') { $tag_str = " EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` = " . DB::escape($tag) . " AND `" . TABLE_PREFIX . "companies`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = 'Companies') "; } $conditions = $wsConditions ? $wsConditions . ($tag_str ? " AND {$tag_str}" : '') : $tag_str; $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND {$conditions}" : ""); $companies = Companies::getVisibleCompanies(logged_user(), $conditions); foreach ($companies as $company) { fwrite($handle, $this->build_csv_from_company($company, $checked_fields) . "\n"); } } fclose($handle); $_SESSION['contact_export_filename'] = $filename; flash_success($imp_type == 'contact' ? lang('success export contacts') : lang('success export companies')); } else { unset($_SESSION['contact_export_filename']); return; } }