3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * * Note that this file is used by the crm project track interface. Make note of that before changing anything. * */ function get_task_statuses($in_options=array()) { $options = array_merge( array( "use_keys"=>false, "display_field"=>"display", "value_field"=>"value" ), $in_options ); $statuses = array( array("On Hold", "On Hold"), array("Awaiting Action", "Awaiting Action"), array("In Progress", "In Progress"), array("Duplicate", "Duplicate"), array("Not a Bug", "Not a Bug"), array("Obsolete", "Obsolete"), array("Completed", "Completed"), array("Completed & Closed", "Completed & Closed") ); if($options["use_keys"]) { $keyed_statuses = array(); for($i = 0; $i < count($statuses); $i++) { $keyed_statuses[] = array( $options["value_field"]=>$statuses[$i][0], $options["display_field"]=>$statuses[$i][1] ); } return $keyed_statuses; } else { return $statuses; } } function get_task_status_x_color() { return array( "On Hold"=>"#F1A7EE", "In Progress"=>"#21F8F0", "Awaiting Action"=>"#E8F100", "Completed"=>"#09F872", "Closed"=>"#F57474" ); } function get_task_priorities($in_options=array()) { $options = array_merge( array( "use_keys"=>false, "display_field"=>"display", "value_field"=>"value" ), $in_options ); $priorities = array( array("High", "High"), array("Moderate", "Moderate"), array("Low", "Low") ); if($options["use_keys"]) { $keyed_priorities = array(); for($i = 0; $i < count($priorities); $i++) { $keyed_priorities[] = array( $options["value_field"]=>$priorities[$i][0], $options["display_field"]=>$priorities[$i][1] ); } return $keyed_priorities; } else { return $priorities; } } function get_task_types($in_options=array()) { $options = array_merge( array( "use_keys"=>false, "display_field"=>"display", "value_field"=>"value" ), $in_options ); $types = array( array("Design", "Design"), array("Documentation", "Documentation"), array("Enhancement", "Enhancement"), array("Implementation", "Implementation"), array("Import", "Import"), array("Modification", "Modification"), array("Move", "Move"), array("Security", "Security"), array("Testing", "Testing") ); if($options["use_keys"]) { $keyed_priorities = array(); for($i = 0; $i < count($types); $i++) { $keyed_priorities[] = array( $options["value_field"]=>$types[$i][0], $options["display_field"]=>$types[$i][1] ); } return $keyed_priorities; } else { return $types; } } function get_bug_types($in_options=array()) { $options = array_merge( array( "use_keys"=>false, "display_field"=>"display", "value_field"=>"value" ), $in_options ); $types = array( array("Modification", "Modification"), array("Error", "Error"), array("Fatal Error", "Fatal Error"), array("Enhancement", "Enhancement"), array("Logical", "Logical"), array("Update", "Update"), array("Idea", "Idea"), array("Uptrak Error", "Uptrak Error") ); if($options["use_keys"]) { $keyed_priorities = array(); for($i = 0; $i < count($types); $i++) { $keyed_priorities[] = array( $options["value_field"]=>$types[$i][0], $options["display_field"]=>$types[$i][1] ); } return $keyed_priorities; } else { return $types; } } /* * This function will determine what email to send based on the records given to us. */ function send_task_email($old_task, $new_task) { global $commonDB, $concept_db, $session; $crm_db = clone($commonDB); $crm_db->select_database("allofe_crm"); if ($new_task["category"] == 1) { $category = 'Bug'; } else if ($new_task["category"] == 2) { $category = 'Task'; } else { $category = $new_task["category"]; } $assigned_to_user_id = $new_task["assigned_to_user_id"]; $user_id = $session->get("user_id"); $following_users = ($new_task["following_user_ids"] == NULL) ? array() : explode(',',$new_task["following_user_ids"]); $send_assigned_email = $send_status_email = $comment_change = $url_change = false; //Send email to assigned user when task is created if($new_task["newtask"]) { if ($new_task['status'] != "Completed") { $send_assigned_email = true; $send_status_email = true; } } else { //Send email to assigned users and following users when task changes hands if ($assigned_to_user_id != $old_task["assigned_to_user_id"]) { $send_assigned_email = true; $send_status_email = true; } //Send email to all users if task changes statuses if ($new_task["status"] != $old_task["status"]) { $send_status_email = true; } //Send email to all users when comments are changed if ($old_task["comments"] && $new_task["comments"]) { if(is_string($old_task["comments"]) && $new_task["comments"] !== $old_task["comments"]) { //sort both of the task's comments to verify that a change isn't in how they are sorted. function commentsCompare($a, $b) { if ($a['date'] == $b['date']) { if ($a['username'] == $b['username']) { if ($a['comment'] == $b['comment']) { return 0; } return ($a['comment'] < $b['comment']) ? -1 : 1; } return ($a['username'] < $b['username']) ? -1 : 1; } return ($a['date'] < $b['date']) ? -1 : 1; } $new_comments = json_decode($new_task["comments"], true); $old_comments = json_decode($old_task["comments"], true); usort($new_comments, "commentsCompare"); usort($old_comments, "commentsCompare"); $new_task["comments"] = json_encode($new_comments); $old_task["comments"] = json_encode($old_comments); if ($new_task["comments"] !== $old_task["comments"]) { $comment_change = true; $send_status_email = true; } } } //Determine which items in the comments have been changed/added if ($comment_change) { $new_comments = json_decode($new_task["comments"], true); $old_comments = json_decode($old_task["comments"], true); $num_old_comments = count($old_comments); $num_new_comments = count($new_comments); for ($i = 0; $i < ($num_old_comments <= $num_new_comments ? $num_old_comments : $num_new_comments); $i++) { if (!$new_comments[$i]) { break; } if ($new_comments[$i]["username"] !== $old_comments[$i]["username"]) { $new_comments[$i]["bold"] = true; } if ($new_comments[$i]["date"] !== $old_comments[$i]["date"]) { $new_comments[$i]["bold"] = true; } if ($new_comments[$i]["comment"] !== $old_comments[$i]["comment"]) { $new_comments[$i]["bold"] = true; } } for ($i = $num_old_comments; $i < $num_new_comments; $i++) { $new_comments[$i]["bold"] = true; } $new_task["comments"] = json_encode($new_comments); $old_task["comments"] = json_encode($old_comments); } //Send email to all users when git_urls are changed if (is_string($old_task["git_urls"]) && $new_task["git_urls"] !== $old_task["git_urls"]) { $url_change = true; $send_status_email = true; } $bolded_urls = array(); //Determine which items in the git_urls have been changed/added if ($url_change) { $new_urls = json_decode($new_task["git_urls"], true); $old_urls = json_decode($old_task["git_urls"], true); $num_new_urls = count($new_urls); $num_old_urls = count($old_urls); for ($i = 0; $i < ($num_old_urls <= $num_new_urls ? $num_old_urls : $num_new_urls); $i++) { if ($new_urls[$i] !== $old_urls[$i]) { $bolded_urls[] = true; } else { $bolded_urls[] = false; } } for ($i = $num_old_urls; $i < $num_new_urls; $i++) { $bolded_urls[] = true; } } } if($send_assigned_email || $send_status_email) { //Gets names and emails of all active users $results = $commonDB->query(" SELECT user_id,first_name,last_name, email FROM users WHERE status = 1" ); $emails = $names = array(); while($record = $results->fetch_next_associative()) { $names[$record["user_id"]] = $record["last_name"].", ".$record["first_name"]; $emails[$record["user_id"]] = $record["email"]; } $user_name = ($names[$user_id]) ? $names[$user_id] : " a Root User"; //Creates contents of email $email_content = array(); $email_content[] = "<b>Category:</b> ". $category; $email_content[] = "<b>Assigned To:</b> ". $names[$assigned_to_user_id]; $email_content[] = "<b>Status:</b> " . $new_task["status"]; $email_content[] = "<b>Priority:</b> " . (($new_task["priority"]) ? $new_task["priority"] : "None"); $email_content[] = "<b>Type:</b> " . $new_task["type"]; $email_content[] = "<b>Project:</b> " . $new_task["project_name"]; if ($new_task["due_date"] && strtoupper($new_task["due_date"]) !== "NULL" && $new_task["due_date"] !== NULL) { $email_content[] = "<b>Due Date:</b>" . date("n/j/Y", strtotime($new_task["due_date"])); } if($new_task["date_completed"] && strtoupper($new_task["date_completed"]) !== "NULL" && $new_task["date_completed"] !== NULL) { $email_content[] = "<b>Completion Date:</b>" . date("n/j/Y", strtotime($new_task["date_completed"])); } if($new_task["system_implementation_id"]) { $system_implementation_name = $commonDB->plookup( "system_implementation_name", "system_implementation", "system_implementation_id = ?", $new_task["system_implementation_id"] ); $email_content[] = "<b>System Implementation:</b> " . $system_implementation_name; } if($new_task["crm_company_id"]) { $crm_company_name = $crm_db->plookup( "name", "crm_companies", "crm_company_id = ?", $new_task["crm_company_id"] ); $email_content[] = "<b>CRM Company:</b> " . $crm_company_name; } if($new_task["allofe_product_id"]) { $allofe_product_name = $concept_db->plookup( "name", "allofe_products", "product_id = ?", $new_task["allofe_product_id"] ); $email_content[] = "<b>AllofE Product:</b> " . $allofe_product_name; } if($new_task["crm_project_track_id"]) { $crm_project_name = $crm_db->plookup( "name", "crm_project_tracks", "crm_project_track_id = ?", $new_task["crm_project_track_id"] ); $email_content[] = "<b>CRM Project:</b> " . $crm_project_name; } if ($new_task["newtask"]) { $creator_name = $user_name; } else { $creator_name = ($names[$old_task["create_user_id"]]) ? $names[$old_task["create_user_id"]] : "Root User"; } $email_content[] = "<b>Creator:</b> ". $creator_name; $email_content[] = "<b>Short Description:</b> " . $new_task["short_description"]; $email_content[] = "<br/><u><b>Long Description</b></u>" . html_entity_decode($new_task["long_description"]); $comments = array(); if($new_task["comments"]) { $comments_json = json_decode($new_task["comments"], true); //inline functions not available in earlier versions of php function commentStatusCompare($a, $b) { if ($a["date"] == $b["date"]) { if($a["comment"]=="(Completed & Closed)" || $a["comment"]=="(Completed)") return -1; else return 1; } return ($a["date"] > $b["date"]) ? -1 : 1; } usort($comments_json, "commentStatusCompare");//it is used once here foreach($comments_json as $comment) { if ($comment["bold"]) { $comments[] = "<b>" . date("n/j/Y", strtotime($comment["date"])) . " - " . $comment["username"] . ":<br/><i>" . $comment["comment"]."</i></b>"; } else { $comments[] = date("n/j/Y", strtotime($comment["date"])) . " - " . $comment["username"] . ":<br/><i>" . $comment["comment"]."</i>"; } } } if($comments) { $email_content[] = "<u><b>Comments</b></u><br/>" . implode("<br/>", $comments); } $git_urls = ""; if ($new_task["git_urls"]) { $git_urls_json = json_decode($new_task["git_urls"],true); $index = 0; foreach($git_urls_json as $git) { if ($bolded_urls[$index]) { $git_urls = $git_urls . "<br/><b>" . $git . "</b>"; } else { $git_urls = $git_urls . "<br/>" . $git; } $index++; } $email_content[] = "<br/><u><b>Git Urls</b></u><br/>" . $git_urls; } $email_text = implode("<br/>",$email_content); //Send email notifying user of new task if they have an email and are not the user that assigned the task if ($send_assigned_email) { if ($emails[$assigned_to_user_id] && $assigned_to_user_id != $user_id) { $m = new Mail(); $m->content_type = "text/html"; $m->To($emails[$assigned_to_user_id]); $m->From($category."s <tasks@allofe.net>"); $m->Subject("New ".$category." Assignment: ". $new_task["short_description"] . " --".$category." ID #" .$new_task["task_id"]); $m->Body(rtrim(chunk_split(base64_encode( "The following ".$category." has been assigned to you by <b>" . $user_name . ":</b><br/><br/>". stripslashes($email_text) ))),"text/html"); $m->ctencoding = "base64"; $m->Send(); } //Removes user from following users array so they don't receive 2 emails unset($following_users[array_search($assigned_to_user_id,$following_users)]); } //Sends status emails to all users that are following the task, excluding the current user if($send_status_email && !empty($following_users)) { foreach($following_users as $following_user_id) { if ($emails[$following_user_id] && $following_user_id != $user_id) { $m = new Mail(); $m->content_type = "text/html"; $m->To($emails[$following_user_id]); $m->From($category."s Tracking<tasks@allofe.net>"); $m->Subject($category." Status Report: " . $new_task["short_description"] . " --".$category." ID #" .$new_task["task_id"]); $m->Body(rtrim(chunk_split(base64_encode( "The following task has been updated by <b>" . $user_name . ":</b><br/><br/>".stripslashes($email_text) ))),"text/html"); $m->ctencoding = "base64"; $m->Send(); } } } } } //Establishing email for reminder function send_reminder_email($old_task, $new_task){ global $commonDB, $session; if ($new_task["category"] == 1) { $category = 'Bug'; } else if ($new_task["category"] == 2) { $category = 'Task'; } else { $category = $new_task["category"]; } //look up emails $emails = array(); $names = array(); $results = $commonDB->pquery( "SELECT user_id,first_name,last_name, email, email_on FROM users WHERE user_id in (?,?,?)", array($new_task["assigned_to_user_id"], $old_task["create_user_id"], $session->stored_data["user_id"]) ); while($record = $results->fetch_next_associative()) { $names[$record["user_id"]] = $record["last_name"].", ".$record["first_name"]; $emails[$record["user_id"]] = $record["email"]; } $email_text = "Type: " . $new_task["type"] . "<br/>" . "Priority: " . (($new_task["priority"])? $new_task["priority"] : "None") . "<br/>" . "Status: " . $new_task["status"] . "<br/>" . "Short Description: ". $new_task["short_description"]."<br/>" . "Long Description: <br/>".$new_task["long_description"]."<br/>" . "Due Date: ". $new_task['due_date']. "<br/>" . "Creator: ". ($names[$old_task["create_user_id"]] ? $names[$old_task["create_user_id"]] : "N/A"). "<br/>" . "Assigned To: ". $names[$new_task["assigned_to_user_id"]]; $m = new Mail(); $m->content_type = "text/html"; $m->To($emails[$new_task["assigned_to_user_id"]]); $m->From("tasks Tracking<tasks@allofe.net>"); $m->Subject("REMINDER: ".$project_name." ".$category." Status Report --".$category." ID #" . $new_task["task_id"] . " Status: " . $new_task["status"]); $m->Body(rtrim(chunk_split(base64_encode( $category." ID: ".$new_task["task_id"]. "<br/>". stripslashes($email_text) ))),"text/html"); $m->ctencoding = "base64"; $m->delaySend($new_task['send_by_date']); $batch_email_id = $m->Send(); return $batch_email_id; } ?>

This is an error 404

There are `0` results


preferences:
1555.87 ms | 1399 KiB | 21 Q