// Else if were not in the installation process and there's no alloc_config.php file then redirect to the installation directory } else { if (!file_exists(ALLOC_MOD_DIR . "alloc_config.php") || !is_readable(ALLOC_MOD_DIR . "alloc_config.php") || filesize(ALLOC_MOD_DIR . "alloc_config.php") < 5 || !defined("ALLOC_DB_NAME")) { alloc_redirect($TPL["url_alloc_installation"]); exit; // Else include the alloc_config.php file and begin with proceedings.. } else { // The timezone must be dealt with before anything else uses it or php will emit a warning $timezone = config::get_config_item("allocTimezone"); date_default_timezone_set($timezone); // Now the timezone is set, replace the missing stuff from the template $TPL["current_date"] = date("Y-m-d H:i:s"); $TPL["today"] = date("Y-m-d"); // The default From: email address if (config::get_config_item("AllocFromEmailAddress")) { define("ALLOC_DEFAULT_FROM_ADDRESS", add_brackets(config::get_config_item("AllocFromEmailAddress"))); } // The default email bounce address define("ALLOC_DEFAULT_RETURN_PATH_ADDRESS", config::get_config_item("allocEmailAdmin")); // If a script has NO_AUTH enabled, then it will perform its own // authentication. And will be responsible for setting up any of: // $current_user and $sess. if (!defined("NO_AUTH")) { $current_user =& singleton("current_user", new person()); $sess = new session(); // If session hasn't been started re-direct to login page if (!$sess->Started()) { defined("NO_REDIRECT") && exit("Session expired. Please <a href='" . $TPL["url_alloc_login"] . "'>log in</a> again."); alloc_redirect($TPL["url_alloc_login"] . ($_SERVER['REQUEST_URI'] != '/' ? '?forward=' . urlencode($_SERVER['REQUEST_URI']) : '')); // Else load up the current_user and continue } else {
if ($percent > 97) { $found = true; #e("percent: ".$percent); #e("1-------------------"); #e($row["comment"]); #e("2-------------------"); #e($body); #e("E-------------------"); } } // If not found, append the comment to the mailbox if (!$found) { e("Appending this comment: " . $row["comment"]); $people_cache =& get_cached_table("person"); $name = $people_cache[$row["commentCreatedUser"]]["name"]; $email = add_brackets($people_cache[$row["commentCreatedUser"]]["emailAddress"]); $eml = array(); $eml[] = "From: " . $name . " " . $email; $eml[] = "Date: " . date('D M j G:i:s Y', strtotime($row["commentCreatedTime"])); $e = new $entity(); $e->set_id($entityID); $e->select(); $tpl = config::get_config_item("emailSubject_" . $entity . "Comment"); $tpl and $subject = commentTemplate::populate_string($tpl, $entity, $entityID); $entity != "task" and $prefix = ucwords($entity) . " Comment: "; $subject or $subject = $prefix . $entityID . " " . $e->get_name(DST_VARIABLE); $r = $db->qr("SELECT tokenHash FROM token WHERE tokenEntity = 'comment' AND tokenEntityID = %d", $row["commentID"]); $subject_header = "Subject: " . $subject . " {Key:" . $r["tokenHash"] . "}"; $eml[] = $subject_header; $recipients = comment::get_email_recipients(array("interested"), $entity, $entityID); list($to_address, $bcc, $successful_recipients) = comment::get_email_recipient_headers($recipients, $people_cache[$row["commentCreatedUser"]]["emailAddress"]);
function attach_email_to_existing_task($req = array()) { global $TPL; $info = inbox::get_mail_info(); $current_user =& singleton("current_user"); $orig_current_user =& $current_user; $req["taskID"] = sprintf("%d", $req["taskID"]); $task = new task(); $task->set_id($req["taskID"]); if ($task->select()) { $email_receive = new email_receive($info); $email_receive->open_mailbox($info["folder"]); $email_receive->set_msg($req["id"]); $email_receive->get_msg_header(); $email_receive->save_email(); $c = comment::add_comment_from_email($email_receive, $task); $commentID = $c->get_id(); $commentID and $TPL["message_good_no_esc"][] = "Created comment " . $commentID . " on task " . $task->get_task_link(array("prefixTaskID" => true)); // Possibly change the identity of current_user list($from_address, $from_name) = parse_email_address($email_receive->mail_headers["from"]); $person = new person(); $personID = $person->find_by_email($from_address); $personID or $personID = $person->find_by_name($from_name); if ($personID) { $current_user = new person(); $current_user->load_current_user($personID); singleton("current_user", $current_user); } // swap back to normal user $current_user =& $orig_current_user; singleton("current_user", $current_user); // manually add task manager and assignee to ip list $extraips = array(); if ($task->get_value("personID")) { $p = new person($task->get_value("personID")); if ($p->get_value("emailAddress")) { $extraips[$p->get_value("emailAddress")]["name"] = $p->get_name(); $extraips[$p->get_value("emailAddress")]["role"] = "assignee"; $extraips[$p->get_value("emailAddress")]["personID"] = $task->get_value("personID"); $extraips[$p->get_value("emailAddress")]["selected"] = 1; } } if ($task->get_value("managerID")) { $p = new person($task->get_value("managerID")); if ($p->get_value("emailAddress")) { $extraips[$p->get_value("emailAddress")]["name"] = $p->get_name(); $extraips[$p->get_value("emailAddress")]["role"] = "manager"; $extraips[$p->get_value("emailAddress")]["personID"] = $task->get_value("managerID"); $extraips[$p->get_value("emailAddress")]["selected"] = 1; } } // add all the other interested parties $ips = interestedParty::get_interested_parties("task", $req["taskID"], $extraips); foreach ((array) $ips as $k => $inf) { $inf["entity"] = "comment"; $inf["entityID"] = $commentID; $inf["email"] and $inf["emailAddress"] = $inf["email"]; if ($req["emailto"] == "internal" && !$inf["external"] && !$inf["clientContactID"]) { $id = interestedParty::add_interested_party($inf); $recipients[] = $inf["name"] . " " . add_brackets($k); } else { if ($req["emailto"] == "default") { $id = interestedParty::add_interested_party($inf); $recipients[] = $inf["name"] . " " . add_brackets($k); } } } $recipients and $recipients = implode(", ", (array) $recipients); $recipients and $TPL["message_good"][] = "Sent email to " . $recipients; // Re-email the comment out comment::send_comment($commentID, array("interested"), $email_receive); // File email away in the task's mail folder $mailbox = "INBOX/task" . $task->get_id(); $email_receive->create_mailbox($mailbox) and $TPL["message_good"][] = "Created mailbox: " . $mailbox; $email_receive->move_mail($req["id"], $mailbox) and $TPL["message_good"][] = "Moved email " . $req["id"] . " to " . $mailbox; $email_receive->close(); } }