/** * chack if $content is spam * * @param string $content */ function isSpam(&$content) { $tokens = Bayesian::getTokens($content); // if there is no tokens, email is most probably not spam if (!is_foreachable($tokens)) { return false; } // if $table_name = TABLE_PREFIX . BAYESIAN_TOKENS_TABLENAME; $total_count_ham = db_execute_one("SELECT count(*) as count FROM `{$table_name}` WHERE `type`='ham'"); $total_count_ham = array_var($total_count_ham, 'count', 0); $total_count_spam = db_execute_one("SELECT count(*) as count FROM `{$table_name}` WHERE `type`='spam'"); $total_count_spam = array_var($total_count_spam, 'count', 0); // there is no learning data if (!$total_count_ham || !$total_count_spam) { } // if $database_tokens = db_execute_all("SELECT * FROM `{$table_name}` WHERE `token` IN (" . implode(',', Bayesian::escapeTokens($tokens)) . ")"); $probabilities = Bayesian::getIndividualProbabilities($tokens, $database_tokens, $total_count_ham, $total_count_spam); return Bayesian::getCombinedProbability($probabilities); // if we don't have good sample rate, we need to mark all $content as spam so we can learn something if ($count_ham + $count_spam < BAYESIAN_INITIAL_THRESHOLD && false) { return true; } // if }
/** * Check if $project is pinned * * @param Project $project * @param User $user * @param boolean $use_cache * @return boolean */ function isPinned($project, $user, $use_cache = true) { if ($use_cache) { $cache_value = cache_get('user_pinned_projects_' . $user->getId()); if (is_array($cache_value)) { return in_array($project->getId(), $cache_value); } else { return in_array($project->getId(), PinnedProjects::rebuildUserCache($user)); } } else { return (bool) array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM " . TABLE_PREFIX . 'pinned_projects WHERE project_id = ? AND user_id = ?', $project->getId(), $user->getId()), 'row_count'); } // if }
/** * Set value of $name config option for a given project * * @param string $name * @param mixed $value * @param Project $project * @return mixed */ function setValue($name, $value, $project) { $option = ConfigOptions::findByName($name, PROJECT_CONFIG_OPTION); if (instance_of($option, 'ConfigOption')) { $table = TABLE_PREFIX . 'project_config_options'; $count = db_execute_one("SELECT COUNT(*) AS 'row_num' FROM {$table} WHERE project_id = ? AND name = ?", $project->getId(), $name); if (isset($count) && $count['row_num'] > 0) { $result = db_execute("UPDATE {$table} SET value = ? WHERE project_id = ? AND name = ?", serialize($value), $project->getId(), $name); } else { $result = db_execute("INSERT INTO {$table} (project_id, name, value) VALUES (?, ?, ?)", $project->getId(), $name, serialize($value)); } // if return $result && !is_error($result) ? $value : $result; } else { return new InvalidParamError('name', $name, "Project configuration option '{$name}' does not exist", true); } // if }
/** * Paginate attachments by project * * @param Project $project * @param User $user * @param integer $page * @param integer $per_page * @param integer $min_state * @return array */ function paginateByProject($project, $user, $page = 1, $per_page = 30, $min_state = STATE_VISIBLE) { $attachments_table = TABLE_PREFIX . 'attachments'; $project_objects_table = TABLE_PREFIX . 'project_objects'; $type_filter = ProjectUsers::getVisibleTypesFilterByProject($user, $project); if ($type_filter) { $total = array_var(db_execute_one("SELECT COUNT({$attachments_table}.id) AS 'row_count' FROM {$attachments_table}, {$project_objects_table} WHERE {$attachments_table}.attachment_type = ? AND {$attachments_table}.parent_id = {$project_objects_table}.id AND {$type_filter} AND {$project_objects_table}.state >= ? AND {$project_objects_table}.visibility >= ?", ATTACHMENT_TYPE_ATTACHMENT, $min_state, $user->getVisibility()), 'row_count'); if ($total) { $offset = ($page - 1) * $per_page; $attachments = Attachments::findBySQL("SELECT {$attachments_table}.* FROM {$attachments_table}, {$project_objects_table} WHERE {$attachments_table}.attachment_type = ? AND {$attachments_table}.parent_id = {$project_objects_table}.id AND {$type_filter} AND {$project_objects_table}.state >= ? AND {$project_objects_table}.visibility >= ? ORDER BY `created_on` DESC LIMIT {$offset}, {$per_page}", array(ATTACHMENT_TYPE_ATTACHMENT, $min_state, $user->getVisibility())); if ($attachments) { return array($attachments, new Pager($page, $total, $per_page)); } // if } // if } // if return array(null, new Pager(1, 0, $per_page)); }
/** * Return number of commits related to a project object * * @param integer $object_id * @param integer $project_id * @return integer */ function countByObject($object) { $object_commits_count = CommitProjectObjects::count("object_id = '" . $object->getId() . "' AND project_id = '" . $object->getProjectId() . "'"); if (instance_of($object, 'Ticket')) { $task_ids = array(); $tasks = db_execute_all("SELECT id FROM " . TABLE_PREFIX . "project_objects WHERE parent_id = " . $object->getid() . " AND `type` = 'Task'"); if (is_foreachable($tasks)) { foreach ($tasks as $task) { $task_ids[] = $task['id']; } // foreach } // if if (is_foreachable($task_ids)) { $related_tasks = db_execute_one("SELECT COUNT(*) AS row_count FROM `" . TABLE_PREFIX . "commit_project_objects` WHERE object_id IN(" . implode(',', $task_ids) . ")"); $object_commits_count += array_var($related_tasks, 'row_count', 0); } // if } //if return $object_commits_count; }
/** * Return number of related time records * * @param void * @return integer */ function countTimeRecords() { if ($this->time_records_count === false) { $this->time_records_count = array_var(db_execute_one("SELECT COUNT(time_record_id) AS 'row_count' FROM " . TABLE_PREFIX . 'invoice_time_records WHERE invoice_id = ?', $this->getId()), 'row_count'); } // if return $this->time_records_count; }
/** * Get total time on project for user * @param Project $project * @param User $user * @return float */ function getTotalUserTimeOnProject($project, $user) { return (double) array_var(db_execute_one("SELECT SUM(float_field_1) AS 'time_sum' FROM " . TABLE_PREFIX . "project_objects WHERE project_id = ? AND integer_field_1 = ?", $project->getId(), $user->getId()), 'time_sum'); }
/** * Return project roles map for a given user * * Returns associative array where key is project ID and value is array of * permissions user has in a given project. System permissions like * administrator, project manager etc are ignored * * @param User $user * @param array $statuses * @return array */ function getProjectRolesMap($user, $statuses = null) { $project_users_table = TABLE_PREFIX . 'project_users'; $projects_table = TABLE_PREFIX . 'projects'; if ($statuses === null) { $rows = db_execute_all("SELECT {$project_users_table}.*, {$projects_table}.name AS 'project_name', {$projects_table}.leader_id AS 'project_leader' FROM {$projects_table}, {$project_users_table} WHERE {$projects_table}.id = {$project_users_table}.project_id AND {$projects_table}.type = ? AND {$project_users_table}.user_id = ? ORDER BY {$projects_table}.name", PROJECT_TYPE_NORMAL, $user->getId()); } else { $rows = db_execute_all("SELECT {$project_users_table}.*, {$projects_table}.name AS 'project_name', {$projects_table}.leader_id AS 'project_leader' FROM {$projects_table}, {$project_users_table} WHERE {$projects_table}.id = {$project_users_table}.project_id AND {$projects_table}.type = ? AND {$projects_table}.status IN (?) AND {$project_users_table}.user_id = ? ORDER BY {$projects_table}.name", PROJECT_TYPE_NORMAL, $statuses, $user->getId()); } // if if (is_foreachable($rows)) { $result = array(); $roles = array(); foreach ($rows as $row) { $project_id = (int) $row['project_id']; $role_id = (int) $row['role_id']; // From role if ($role_id) { if (!isset($roles[$role_id])) { $role_row = db_execute_one('SELECT permissions FROM ' . TABLE_PREFIX . 'roles WHERE id = ?', $role_id); if ($role_row && isset($role_row['permissions'])) { $roles[$role_id] = $role_row['permissions'] ? unserialize($role_row['permissions']) : array(); } else { $roles[$role_id] = array(); } // if } // if $result[$project_id] = array('name' => $row['project_name'], 'leader' => $row['project_leader'], 'permissions' => $roles[$role_id]); // From permissions } else { $result[$project_id] = array('name' => $row['project_name'], 'leader' => $row['project_leader'], 'permissions' => $row['permissions'] ? unserialize($row['permissions']) : array()); } // if } // foreach return $result; } // if return null; }
/** * This validator will return true if $value is unique (there is no row with such value in that field) * * @param string $field Filed name * @param mixed $value Value that need to be checked * @return boolean */ function validateUniquenessOf($field) { // Don't do COUNT(*) if we have one PK column $escaped_pk = is_array($pk_fields = $this->getPrimaryKey()) ? '*' : $pk_fields; // Get columns $fields = func_get_args(); if (!is_array($fields) || count($fields) < 1) { return true; } // if // Check if we have existsing columns foreach ($fields as $field) { if (!$this->fieldExists($field)) { return false; } // if } // foreach // Get where parets $where_parts = array(); foreach ($fields as $field) { $where_parts[] = $field . ' = ' . db_escape($this->values[$field]); } // if // If we have new object we need to test if there is any other object // with this value. Else we need to check if there is any other EXCEPT // this one with that value if ($this->isNew()) { $sql = sprintf("SELECT COUNT({$escaped_pk}) AS 'row_count' FROM %s WHERE %s", $this->getTableName(), implode(' AND ', $where_parts)); } else { // Prepare PKs part... $pks = $this->getPrimaryKey(); $pk_values = array(); if (is_array($pks)) { foreach ($pks as $pk) { if (isset($this->primary_key_updated[$pk]) && $this->primary_key_updated[$pk]) { $primary_key_value = $this->old_values[$pk]; } else { $primary_key_value = $this->values[$pk]; } // if $pk_values[] = sprintf('%s <> %s', $pk, db_escape($primary_key_value)); } // foreach } // if // Prepare SQL $sql = sprintf("SELECT COUNT({$escaped_pk}) AS 'row_count' FROM %s WHERE (%s) AND (%s)", $this->getTableName(), implode(' AND ', $where_parts), implode(' AND ', $pk_values)); } // if $row = db_execute_one($sql); return array_var($row, 'row_count', 0) < 1; }
/** * Return number of rows in this table * * @param string $conditions Query conditions * @param string $table_name * @return integer * @throws DBQueryError */ function count($conditions = null, $table_name = null) { $conditions = DataManager::prepareConditions($conditions); $where_string = trim($conditions) == '' ? '' : "WHERE {$conditions}"; $row = db_execute_one("SELECT COUNT(*) AS 'row_count' FROM `{$table_name}` {$where_string}"); return (int) array_var($row, 'row_count', 0); }
/** * Return value of priority field * * @param void * @return integer */ function getPriority() { //return $this->getFieldValue('priority'); $cur_priority = $this->getFieldValue('priority'); if ($this->getType() == 'Task' && $cur_priority == '0') { $row = db_execute_one("select isnull(priority) as is_empty_priority from " . TABLE_PREFIX . "project_objects where id='" . $this->getId() . "'"); return $row['is_empty_priority'] ? '-99' : $cur_priority; } else { return $cur_priority; } }
/** * Return ID for next ticket * * $project can be an instance of Project class or project_id * * @param Project $project * @return integer */ function findNextTicketIdByProject($project) { $project_id = instance_of($project, 'Project') ? $project->getId() : (int) $project; $project_objects_table = TABLE_PREFIX . 'project_objects'; $row = db_execute_one("SELECT MAX(integer_field_1) AS 'max_id' FROM {$project_objects_table} WHERE project_id = ? AND type = ?", $project_id, 'Ticket'); if (is_array($row)) { return $row['max_id'] + 1; } else { return 1; } // if }
function get_action_request_comment_body() { $body = ''; $row = db_execute_one("select comment_id from actionrequests_to_tasklist where object_id='" . $this->getId() . "'"); if ($row) { if (!empty($row['comment_id'])) { $comment = new Comment($row['comment_id']); $body = strip_tags($comment->getBody(), '<p>') . '<br/><a href="' . $comment->getViewUrl() . '">Click to View Comment</a>'; } } return $body; }
/** * Returns true if $object is viewed by $user * * @param ProjectObject $object * @param User $user * @return boolan */ function isViewed($object, $user) { return (bool) array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM " . TABLE_PREFIX . 'project_object_views WHERE object_id = ? AND created_by_id = ?', $object->getId(), $user->getId()), 'row_count'); }
/** * Subscribe array of users to the object * * If $replace is set to true, all subscriptions for this object will be * dropped and $users will be subscribed to it * * @param array $users * @param ProjectObject $object * @param boolean $replace * @return boolean */ function subscribeUsers($users, $object, $replace = true) { db_begin_work(); $object_id = (int) $object->getId(); if ($object_id) { $subscriptions_table = TABLE_PREFIX . 'subscriptions'; if ($replace) { Subscriptions::deleteByParent($object); // cleanup } // if $to_subscribe = array(); if (is_foreachable($users)) { foreach ($users as $user) { if (instance_of($user, 'User')) { $user_id = (int) $user->getId(); } else { $user_id = (int) $user; } // if if ($user_id) { if (isset($to_subscribe[$user_id])) { continue; // duplicate user ID! } else { if (!$replace && array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM {$subscriptions_table} WHERE user_id = ? AND parent_id = ?", $user_id, $object_id), 'row_count') > 0) { continue; // Make sure that we do not have this user already subscribed } // if cache_remove("user_subscriptions_{$user_id}"); $to_subscribe[$user_id] = "({$user_id}, {$object_id})"; } // if } // if } // foreach } // if // Insert subscriptions if (is_foreachable($to_subscribe)) { $insert = db_execute("INSERT INTO {$subscriptions_table} VALUES " . implode(', ', $to_subscribe)); if (!$insert || is_error($insert)) { db_rollback(); return $insert; } // if } // if } // if db_commit(); return true; }
/** * Return number of users who have $name config option set to $value * * @param string $name * @param mixed $value * @param array $excude_ids * @return integer */ function countByValue($name, $value, $excude_ids = null) { if ($excude_ids && !is_array($excude_ids)) { $excude_ids = array($excude_ids); } // if $rows = db_execute_all('SELECT user_id, value FROM ' . TABLE_PREFIX . 'user_config_options WHERE name = ?', $name); if (is_foreachable($rows)) { $user_ids = array(); foreach ($rows as $row) { if (unserialize($row['value']) == $value) { if ($excude_ids) { if (in_array($row['user_id'], $excude_ids)) { continue; } // if } // if $user_ids[] = (int) $row['user_id']; } // if } // foreach if (is_foreachable($user_ids)) { return array_var(db_execute_one("SELECT COUNT(id) AS 'row_count' FROM " . TABLE_PREFIX . 'users WHERE id IN (?)', $user_ids), 'row_count'); } // if } // if return 0; }
/** * write locale properties * * @param string $subject * @param string $body * @param string $locale * @return boolean */ function writeLocaleProperties($subject, $body, $locale) { $count = (int) array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM " . TABLE_PREFIX . 'email_template_translations WHERE name = ? AND module = ? AND locale = ?', $this->getName(), $this->getModule(), $locale), 'row_count'); if ($count) { return db_execute('UPDATE ' . TABLE_PREFIX . 'email_template_translations SET subject = ?, body = ? WHERE name = ? AND module = ? AND locale = ?', $subject, $body, $this->getName(), $this->getModule(), $locale); } else { return db_execute('INSERT INTO ' . TABLE_PREFIX . 'email_template_translations (name, module, locale, subject, body) VALUES (?, ?, ?, ?, ?)', $this->getName(), $this->getModule(), $locale, $subject, $body); } // if }
/** * Return portal project recent activities * * @param Portal $portal * @param integer $page * @param integer $per_page * @return array */ function paginatePortalProjectRecentActivities($portal, $page = 1, $per_page = 30) { $type_filter = Portal::getVisibleTypesFilterByPortalProject($portal); if ($type_filter) { $objects_table = TABLE_PREFIX . 'project_objects'; $logs_table = TABLE_PREFIX . 'activity_logs'; $count = array_var(db_execute_one("SELECT COUNT({$logs_table}.id) AS 'row_count' FROM {$logs_table}, {$objects_table} WHERE {$logs_table}.object_id = {$objects_table}.id AND {$objects_table}.project_id = ? AND {$type_filter} AND {$objects_table}.state >= ? AND {$objects_table}.visibility >= ?", $portal->getProjectId(), STATE_DELETED, VISIBILITY_NORMAL), 'row_count'); if ($count) { $offset = ($page - 1) * $per_page; $recent_activities = ActivityLogs::findBySQL("SELECT {$logs_table}.* FROM {$logs_table}, {$objects_table} WHERE {$logs_table}.object_id = {$objects_table}.id AND {$objects_table}.project_id = ? AND {$type_filter} AND {$objects_table}.state >= ? AND {$objects_table}.visibility >= ? ORDER BY {$logs_table}.created_on DESC LIMIT {$offset}, {$per_page}", array($portal->getProjectId(), STATE_DELETED, VISIBILITY_NORMAL)); } else { $recent_activities = null; } // if return array($recent_activities, new Pager($page, $count, $per_page)); } else { return null; } // if }
/** * Return total number of changes recorded for a specific ticket * * @param Ticket $ticket * @return integer */ function countByTicket($ticket) { return (int) array_var(db_execute_one("SELECT COUNT(id) AS 'row_count' FROM " . TABLE_PREFIX . 'ticket_changes WHERE ticket_id = ?', $ticket->getId()), 'row_count'); }
/** * Set value of $name config option for a given company * * @param string $name * @param mixed $value * @param Company $company * @return mixed */ function setValue($name, $value, $company) { $option = ConfigOptions::findByName($name, COMPANY_CONFIG_OPTION); if (instance_of($option, 'ConfigOption')) { $table = TABLE_PREFIX . 'company_config_options'; $count = db_execute_one("SELECT COUNT(*) AS 'row_num' FROM {$table} WHERE company_id = ? AND name = ?", $company->getId(), $name); if (isset($count) && $count['row_num'] > 0) { $result = db_execute("UPDATE {$table} SET value = ? WHERE company_id = ? AND name = ?", serialize($value), $company->getId(), $name); } else { $result = db_execute("INSERT INTO {$table} (company_id, name, value) VALUES (?, ?, ?)", $company->getId(), $name, serialize($value)); } // if if ($result && !is_error($result)) { $cache_id = 'company_config_options_' . $company->getId(); $cached_values = cache_get($cache_id); if (is_array($cached_values)) { $cached_values[$name] = $value; } else { $cached_values = array($name => $value); } // if cache_set($cache_id, $cached_values); return $value; } else { return $result; } // if } else { return new InvalidParamError('name', $name, "Company configuration option '{$name}' does not exist", true); } // if }
/** * Return number of users who were online in the past $minutes minutes * * @param User $user * @param integer $minutes * @return array */ function countWhoIsOnline($user, $minutes = 15) { $visible_user_ids = Users::findVisibleUserIds($user); if (is_foreachable($visible_user_ids)) { $users_table = TABLE_PREFIX . 'users'; $reference = new DateTimeValue("-{$minutes} minutes"); return array_var(db_execute_one("SELECT COUNT(id) AS 'row_count' FROM {$users_table} WHERE id IN (?) AND last_activity_on > ?", $visible_user_ids, $reference), 'row_count'); } // if return 0; }
/** * Returns true if we already have an search index for a given entry * * @param integer $object_id * @param string $type * @return boolean */ function hasObject($object_id, $type) { $search_index_table = TABLE_PREFIX . 'search_index'; return (bool) array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM {$search_index_table} WHERE object_id = ? AND type = ?", $object_id, $type), 'row_count'); }
/** * Return total amount paid for a given invoice * * @param Invoice $invoice * @return float */ function sumByInvoice($invoice) { return (double) array_var(db_execute_one("SELECT SUM(amount) AS 'amount_paid' FROM " . TABLE_PREFIX . 'invoice_payments WHERE invoice_id = ?', $invoice->getId()), 'amount_paid'); }
/** * Return client company ID * * $project can be Project instance of project id (as integer) * * @param Project $project * @return integer */ function findClientId($project) { $project_id = instance_of($project, 'Project') ? $project->getId() : (int) $project; return array_var(db_execute_one('SELECT company_id FROM ' . TABLE_PREFIX . 'projects WHERE id = ?', $project_id), 'company_id', null); }
/** * Find and return a specific module by name * * @param string $name * @return Module */ function findById($name) { if (empty($name)) { return null; } // if $module_class = Inflector::camelize($name) . 'Module'; require_once APPLICATION_PATH . "/modules/{$name}/{$module_class}.class.php"; $cache_id = TABLE_PREFIX . 'modules_name_' . $name; $row = cache_get($cache_id); if ($row) { $module = new $module_class(); $module->loadFromRow($row); return $module; } else { $row = db_execute_one("SELECT * FROM " . TABLE_PREFIX . "modules WHERE name = ? LIMIT 0, 1", $name); if (is_array($row)) { $module = new $module_class(); $module->loadFromRow($row); return $module; } // if } // if return null; }
/** * Find and return a specific project object by ID * * This function will make sure that we ruturn instance of proper class (it * will read the type of the object and construct object of that class) * * @param mixed $id * @return ProjectObject */ function findById($id) { if (empty($id)) { return null; } // if $cache_id = TABLE_PREFIX . 'project_objects_id_' . $id; $row = cache_get($cache_id); if ($row) { $object_class = $row['type']; $object = new $object_class(); $object->loadFromRow($row); return $object; } else { $row = db_execute_one("SELECT * FROM " . TABLE_PREFIX . "project_objects WHERE id = ? LIMIT 0, 1", $id); if (is_array($row)) { $object_class = $row['type']; $object = new $object_class(); $object->loadFromRow($row, true); return $object; } // if } // if return null; }
function importPendingEmailAsComment(&$incoming_mail, &$project, &$user, &$mailbox, $page_id = '') { $parent = ProjectObjects::findById(!empty($page_id) ? $page_id : $incoming_mail->getParentId()); //EOF:mod 20120820 if (!instance_of($parent, 'ProjectObject')) { // parent object does not exists $incoming_mail->setState(INCOMING_MAIL_STATUS_PARENT_NOT_EXISTS); $incoming_mail_save = $incoming_mail->save(); return new Error(incoming_mail_module_get_status_description(INCOMING_MAIL_STATUS_PARENT_NOT_EXISTS)); } // if if (!$mailbox->getAcceptAllRegistered() && instance_of($user, 'User') && !$parent->canComment($user)) { // user cannot create comments to parent object $incoming_mail->setState(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT); $incoming_mail_save = $incoming_mail->save(); return new Error(incoming_mail_module_get_status_description(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT)); } else { if (!$parent->can_have_comments || $parent->getIsLocked() || $parent->getState() < STATE_VISIBLE) { // parent object can't have comments $incoming_mail->setState(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT); $incoming_mail_save = $incoming_mail->save(); return new Error(incoming_mail_module_get_status_description(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT)); } // if } // if $comment = new Comment(); $comment->log_activities = false; $comment->setCreatedBy($user); $comment->setCreatedOn($incoming_mail->getCreatedOn()); $comment->setProjectId($parent->getProjectId()); $comment->setState(STATE_VISIBLE); $comment->setSource(OBJECT_SOURCE_EMAIL); $comment->setVisibility($parent->getVisibility()); $comment->setParent($parent); $body_content = ''; if (stripos($incoming_mail->getBody(), '-- REPLY ABOVE THIS LINE --') !== false) { $body_content = substr($incoming_mail->getBody(), 0, strpos($incoming_mail->getBody(), '-- REPLY ABOVE THIS LINE --')); } else { $body_content = $incoming_mail->getBody(); } $comment->setBody($body_content); IncomingMailImporter::attachFilesToProjectObject($incoming_mail, $comment); //$save = $comment->save(); $save = $comment->save(true); if ($save && !is_error($save)) { $activity = new NewCommentActivityLog(); $activity->log($comment, $user); if (instance_of($user, 'User')) { $parent->subscribe($user); } // if $comment->ready(); //BOF:mod 20111110 #493 preg_match("/\\[CID(.*?)\\](.*)/is", $incoming_mail->getSubject(), $results); if (count($results) > 0) { $project = new Project($parent->getProjectId()); $variables = array('owner_company_name' => get_owner_company(), 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'object_type' => $comment->getVerboseType(), 'object_name' => $comment->getName(), 'object_body' => $comment->getFormattedBody(), 'object_url' => $comment->getViewUrl(), 'comment_body' => $comment->getFormattedBody(), 'comment_url' => $comment->getViewUrl(), 'created_by_url' => $user->getViewUrl(), 'created_by_name' => $user->getDisplayName(), 'details_body' => '', 'comment_id' => $comment->getId()); $emailed_comment_id = $results[1]; $emailed_comment = new Comment($emailed_comment_id); $emailed_comment_creator_id = $emailed_comment->getCreatedById(); $email_to = array(); $temp_user_id = $user->getId(); $temp_comment_id = $comment->getId(); $rows = db_execute_all("select user_id from " . TABLE_PREFIX . "assignments_action_request where comment_id='" . $emailed_comment_id . "' and marked_for_email='1'"); foreach ($rows as $row) { if ($row['user_id'] != $temp_user_id) { $email_to[] = new User($row['user_id']); db_execute("insert into " . TABLE_PREFIX . "assignments_action_request (user_id, marked_for_email, selected_by_user_id, comment_id, date_added) values ('" . $row['user_id'] . "', '1', '" . $temp_user_id . "', '" . $temp_comment_id . "', now())"); } } $row = db_execute_one("select a.selected_by_user_id from " . TABLE_PREFIX . "assignments_action_request a where a.comment_id='" . $emailed_comment_id . "' and a.marked_for_email='1' and a.selected_by_user_id not in (select b.user_id from " . TABLE_PREFIX . "assignments_action_request b where b.comment_id='" . $emailed_comment_id . "' and b.marked_for_email='1') limit 0, 1"); if (!empty($row['selected_by_user_id'])) { if ($row['selected_by_user_id'] != $temp_user_id) { $email_to[] = new User($row['selected_by_user_id']); db_execute("insert into " . TABLE_PREFIX . "assignments_action_request (user_id, marked_for_email, selected_by_user_id, comment_id, date_added) values ('" . $row['selected_by_user_id'] . "', '1', '" . $temp_user_id . "', '" . $temp_comment_id . "', now())"); } } //ApplicationMailer::send(array(new User($emailed_comment_creator_id)), 'resources/new_comment', $variables, $parent); $attachments = null; $object_attachments = $comment->getAttachments(); if ($object_attachments) { $attachments = array(); foreach ($object_attachments as $object_attachment) { $attachments[] = array('path' => $object_attachment->getFilePath(), 'name' => $object_attachment->getName(), 'mime_type' => $object_attachment->getMimeType()); } } ApplicationMailer::send($email_to, 'resources/new_comment', $variables, $parent, $attachments); } //EOF:mod 20111110 #493 if (!empty($page_id)) { //$link = mysql_connect(DB_HOST, DB_USER, DB_PASS); //mysql_select_db(DB_NAME, $link); //mysql_query("insert into testing (date_added, content) values (now(), 'Page_id: " . $page_id . "')"); //mysql_close($link); $task =& IncomingMailImporter::importPendingEmailToTaskList($incoming_mail, $project, $user, $page_id, $comment); return $task; } else { return $comment; } } // if return $save; }