/** * Register action : create a new account * @access public * @return void */ public function register() { $this->form = new UserCreateForm(); if ($this->request->is_post()) { if (!$this->form->is_valid($this->params['account'])) { $this->flash['error'] = __('Fail to create account : Check data.'); return; } $this->user = new User($this->form->cleaned_data); if (!$this->user->save()) { $this->form->errors = new SFormErrors($this->user->errors); $this->flash['error'] = __('Fail to create account : Check data.'); return; } $logger = new SLogger('../log/account.log'); $logger->info("{$this->user->login} ({$this->user->id}) signup"); $this->session['user'] = $this->user; $mailer = new ApplicationMailer(); $mailer->send_signup_notification($this->user); $this->redirect_to(home_url()); } }
/** * Lost action : if user has lost his password * @access public * @return void */ public function lost() { $this->form = new LostLoginForm(); $req = new SRequestParams(); if ($this->request->is_post()) { if ($this->form->is_valid($this->params['user'])) { try { $user = User::$objects->get('email = ?', array($this->params['user']['email'])); $mailer = new ApplicationMailer(); $mailer->send_password_reminder($user); $logger = new SLogger('../log/account.log'); $logger->info("{$user->login} ({$user->id}) password reminder sent to <{$user->email}>"); $this->flash['notice'] = __('Password reminder has been sent to you by email'); $this->redirect_to_login(); return; } catch (SRecordNotFound $e) { $this->flash['error'] = __('This email address is not registered'); $this->form->errors = new SFormErrors(array('email' => __('Email not found'))); return; } } $this->flash['error'] = __('You have to give a valid registered email address.'); } }
private function RFCDate() { $tz = date("Z"); $tzs = $tz < 0 ? "-" : "+"; $tz = abs($tz); $tz = $tz / 3600 * 100 + $tz % 3600 / 60; $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz); return $result; } private function fixEOL($str) { $str = str_replace("\r\n", "\n", $str); $str = str_replace("\r", "\n", $str); $str = str_replace("\n", $this->LE, $str); return $str; } private function wrapText($str) { } } class Part { private $contentType = ""; } class User { public $email = '*****@*****.**'; } ApplicationMailer::create('signupNotification', new User()); ApplicationMailer::deliver();
/** * Send error log to administrator * * @param array $errors * @return boolean */ function backup_module_log_error($errors, $send_email = false) { $log_message = is_foreachable($errors) ? implode("\n", $errors) : $errors; if ($send_email) { $mailer =& ApplicationMailer::mailer(); $recipient = new Swift_Address(); $recipient->setAddress(ADMIN_EMAIL); $recipient->setName('activeCollab admin'); $sender = new Swift_Address(); $sender->setAddress(ConfigOptions::getValue('notifications_from_email')); $sender->setName(ConfigOptions::getValue('notifications_from_name')); $tmp_message = "Automatic backup of activeCollab on " . ROOT_URL . " failed.\n\r"; $tmp_message .= "Backup returned these errors: \n\r\n\r"; $tmp_message .= $log_message; $message = new Swift_Message(); $message->setSubject('activeCollab automatic backup error log'); $message->setData($tmp_message); $message->setContentType('text/plain'); $mailer->send($message, $recipient, $sender); } // if log_message($log_message, LOG_LEVEL_ERROR, 'backup'); }
/** * Return mailer instance * * @param void * @return Swift */ function &mailer() { $instance =& ApplicationMailer::instance(); if (!$instance->connected) { $instance->connect(); } // if return $instance->swift; }
/** * Do daily taks * * @param void * @return null */ function system_handle_on_daily() { ProjectObjectViews::cleanUp(); $priorities_images = array(PRIORITY_URGENT => 'assets/images/icons/priority/urgent.png', PRIORITY_HIGHEST => 'assets/images/icons/priority/highest.gif', PRIORITY_HIGH => 'assets/images/icons/priority/high.gif', PRIORITY_NORMAL => 'assets/images/icons/priority/normal.gif', PRIORITY_LOW => 'assets/images/icons/priority/low.gif', PRIORITY_LOWEST => 'assets/images/icons/priority/lowest.gif', PRIORITY_HOLD => 'assets/images/icons/priority/hold.png', '-99' => 'assets/images/icons/priority/unknown.png'); $pages = array(); $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $sql = "select id, name from healingcrystals_project_objects where project_id='" . TASK_LIST_PROJECT_ID . "' and type='Page'"; $result = mysql_query($sql, $link); while ($entry = mysql_fetch_assoc($result)) { list($name, ) = explode('-', $entry['name']); $name = trim($name); $pages[$name] = $entry['id']; } $current_time = time(); $users = Users::findAll(); foreach ($users as $user) { $flag = 1; $message = ''; $name = $user->getName(); if (array_key_exists($name, $pages)) { $page = new Page($pages[$name]); if ($page) { $sql = "select id from healingcrystals_project_objects where parent_id='" . $pages[$name] . "' and parent_type='Page' and type='Task' and completed_on is null and priority is null and created_on>='" . date('Y-m-d H:i:s', $current_time - 1 * 24 * 60 * 60) . "' order by created_on"; $result = mysql_query($sql, $link); if (mysql_num_rows($result)) { $show_task_list = true; } else { $show_task_list = false; } if (date('N') == '1' || $show_task_list) { $message .= '<style> .odd {background-color:#ffffff;} .even{background-color:#eeeeee;} </style> <table> <tr> <td colspan="3">Task List: ' . $name . '</td> </tr> <tr> <td align="center">Priority</td> <td>Task</td> <td> </td> </tr>'; $tasks = Tasks::findOpenByObject($page); foreach ($tasks as $task) { $message .= ' <tr class="' . ($flag % 2 === 1 ? 'odd' : 'even') . '"> <td valign="top" align="center"><img src="http://projects.ffbh.org/public/' . $priorities_images[$task->getPriority()] . '"/></td> <td valign="top">' . $task->getName() . '</td> <td valign="top"><a href="' . $task->getViewUrl() . '">View</a></td> </tr>'; $flag++; } $message .= ' </table>'; $subject = 'projects: healingcrystals.com Task list'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: FFBH Reminder <*****@*****.**>' . "\r\n"; mail($user->getEmail(), $subject, $message, $headers); } } } } $sql = "select po.id, cast(if( pom.recurring_period_type='D', DATE_ADD(po.due_on, interval pom.recurring_period day), if(pom.recurring_period_type='W', DATE_ADD(po.due_on, interval pom.recurring_period week), if(pom.recurring_period_type='M', DATE_ADD(po.due_on, interval pom.recurring_period month), null ) ) ) as Date) as next_due_date, cast(DATE_ADD(now(), interval 0 day) as Date) as cur_date, cast(if(isnull(pom.email_reminder_unit), null, if( pom.email_reminder_unit='D', DATE_ADD(po.due_on, interval pom.email_reminder_period day), if(pom.email_reminder_unit='W', DATE_ADD(po.due_on, interval pom.email_reminder_period week), if(pom.email_reminder_unit='M', DATE_ADD(po.due_on, interval pom.email_reminder_period month), null ) ) )\t) as Date) as reminder_date from healingcrystals_project_objects po inner join healingcrystals_project_object_misc pom on po.id=pom.object_id where po.type='Task' and po.due_on is not null and po.due_on<=now() and po.completed_on is null and pom.recurring_period_condition='after_due_date' and if(pom.recurring_end_date is not null and pom.recurring_end_date!='0000-00-00', if(pom.recurring_end_date>=now(), 1, 0), 1)=1 having next_due_date=cur_date"; $result = mysql_query($sql); while ($entry = mysql_fetch_assoc($result)) { $task = new Task($entry['id']); $action = $task->complete(new AnonymousUser('auto', '*****@*****.**')); if (!empty($entry['reminder_date']) && $entry['cur_date'] == $entry['reminder_date']) { $sql02 = "select id from " . TABLE_PREFIX . "project_objects where type='Task' and project_id='" . $task->getProjectId() . "' and milestone_id='" . $task->getMilestoneId() . "' and parent_id='" . $task->getParentId() . "' order by id desc limit 0, 1"; $result02 = mysql_query($sql02); if (mysql_num_rows($result02)) { $info = mysql_fetch_assoc($result02); $recurring_task = new Task($info['id']); $parent = $recurring_task->getParent(); $project = $recurring_task->getProject(); $assignees = $recurring_task->getAssignees(); $priorities = array(PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_ONGOING => lang('Ongoing'), PRIORITY_HOLD => lang('Hold')); $due_date = $task->getDueOn(); $due_date = date('m/d/Y', strtotime($due_date)); $reminder_date = date('m/d/Y', strtotime($entry['reminder_date'])); foreach ($assignees as $assignee) { $assignees_string .= $assignee->getDisplayName() . ', '; } if (!empty($assignees_string)) { $assignees_string = substr($assignees_string, 0, -2); } else { $assignees_string = '--'; } $reminders_sent = array(); foreach ($assignees as $user) { //if ($user->getEmail()=='*****@*****.**'){ $reminder = new Reminder(); $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $recurring_task->getId(), 'comment' => $comment)); $save = $reminder->save(); if ($save && !is_error($save)) { $reminders_sent[] = $user->getDisplayName(); ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => 'AutoReminder', 'reminded_by_url' => '', 'object_name' => $recurring_task->getName(), 'object_url' => $recurring_task->getViewUrl(), 'object_type' => strtolower($recurring_task->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'ticket_name' => $parent->getName(), 'ticket_url' => $parent->getViewUrl(), 'object_priority' => $priorities[(string) $recurring_task->getPriority()], 'object_due_date' => $due_date, 'object_reminder_date_n_time' => $reminder_date, 'object_assignees' => $assignees_string, 'task_mark_complete_url' => $recurring_task->getCompleteUrl() . '&auto=1', 'display_status_for_complete_url' => $recurring_task->is_action_request_task() ? '' : 'none'), $recurring_task); } //} } } } } mysql_close($link); }
/** * Set_expired action : update achievement state to expired * (unlocked and expired achievements can't be modified) * @access public * @return void */ public function set_expired() { if (!$this->_load_achievement()) { $this->redirect_to(home_url()); return; } if (!$this->achievement->is_locked() || !$this->session['user']->is_creator_of($this->achievement)) { $this->flash['error'] = __('You can\'t modify this achievement.'); $this->redirect_to(home_url()); return; } $this->achievement->state = 'expired'; if (!$this->achievement->save()) { $this->form->errors = $this->achievement->errors; $this->flash['error'] = __('Fail to update achievement : Check data.'); return; } must_regenerate_achievement($this->achievement); $this->redirect_to(home_url()); $mailer = new ApplicationMailer(); $mailer->send_achievement_expired_notification($this->achievement); }
/** * Do hourly tasks * * @param void * @return null */ function system_handle_on_hourly() { $cache =& Cache::instance(); if (instance_of($cache->backend, 'CacheBackend')) { $cache->backend->cleanup(); } // if //BOF:mod $time_current = $time_end = time() - 4 * 60 * 60; $time_start = $time_end - 60 * 60; $comment = 'Auto Reminder'; $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); //BOF:mod 20120816 /* //EOF:mod 20120816 $query = "select distinct a.object_id from healingcrystals_project_object_misc a inner join healingcrystals_project_objects b on a.object_id=b.id where b.type='Task' and b.state='" . STATE_VISIBLE . "' and (b.completed_on is null or b.completed_on='') and a.reminder_date is not null and a.reminder_date<>'0000-00-00' and a.auto_email_status='1' and ((a.reminder_date between '" . date('Y-m-d H:i:s', $time_start) . "' and '" . date('Y-m-d H:i:s', $time_end) . "') or (a.recurring_period_type = 'D' and recurring_period = '1' and recurring_period_condition = 'after_due_date' and (recurring_end_date > '".date('Y-m-d')."' or recurring_end_date = '0000-00-00') and date_format(a.reminder_date,'%H:%i:%s') between '" . date('H:i:s', $time_start) . "' and '" . date('H:i:s', $time_end) . "'))"; mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($query) . "')"); //BOF:mod 20120816 */ /* $query = "select distinct a.object_id, a.reminder_date from healingcrystals_project_object_misc a inner join healingcrystals_project_objects b on a.object_id=b.id where b.type='Task' and b.state='" . STATE_VISIBLE . "' and (b.completed_on is null or b.completed_on='') and a.reminder_date is not null and a.reminder_date<>'0000-00-00' and a.auto_email_status='1' and ((a.reminder_date between '" . date('Y-m-d H:i:s', $time_start) . "' and '" . date('Y-m-d H:i:s', $time_end) . "') or (a.recurring_period_type = 'D' and recurring_period = '1' and recurring_period_condition = 'after_due_date' and (recurring_end_date > '".date('Y-m-d')."' or recurring_end_date = '0000-00-00') and date_format(a.reminder_date,'%H:%i:%s') between '" . date('H:i:s', $time_start) . "' and '" . date('H:i:s', $time_end) . "'))"; */ $query = "select distinct \n\t\t\t\ta.object_id, \n\t\t\t\tcast(if(a.email_reminder_unit='D', \n\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period day), ' ', a.email_reminder_time), \n\t\t\t\t\tif(a.email_reminder_unit='W', \n\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period week), ' ', a.email_reminder_time), \n\t\t\t\t\t\tif(a.email_reminder_unit='M', \n\t\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period month), ' ', a.email_reminder_time), \n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) as datetime) as reminder \n\t\t\t from \n\t\t\t\thealingcrystals_project_object_misc a \n\t\t\t\tinner join healingcrystals_project_objects b on a.object_id=b.id \n\t\t\t where \n\t\t\t\tb.type='Task' and \n\t\t\t\tb.state='" . STATE_VISIBLE . "' and \n\t\t\t\t(b.completed_on is null or b.completed_on='') and \n\t\t\t\ta.auto_email_status='1' and \n\t\t\t\ta.email_reminder_unit is not null and \n\t\t\t\tb.due_on is not null and \n\t\t\t\t(a.snooze_datetime is null or a.snooze_datetime='0000-00-00 00:00:00' or a.snooze_datetime<'" . date('Y-m-d H:i:s', $time_current) . "') and \n\t\t\t\tcast(if(a.email_reminder_unit='D', \n\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period day), ' ', a.email_reminder_time), \n\t\t\t\t\tif(a.email_reminder_unit='W', \n\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period week), ' ', a.email_reminder_time), \n\t\t\t\t\t\tif(a.email_reminder_unit='M', \n\t\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period month), ' ', a.email_reminder_time), \n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) as datetime) between '" . date('Y-m-d H:i:s', $time_start) . "' and '" . date('Y-m-d H:i:s', $time_end) . "'\n\t\t\t "; //EOF:mod 20120816 $result = mysql_query($query, $link); while ($entry = mysql_fetch_assoc($result)) { $task_obj = new Task($entry['object_id']); $parent = $task_obj->getParent(); $project = $task_obj->getProject(); $assignees = $task_obj->getAssignees(); //BOF:mod 20120816 $priorities = array(PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_ONGOING => lang('Ongoing'), PRIORITY_HOLD => lang('Hold')); $due_date = $task_obj->getDueOn(); if (!empty($due_date) && $due_date != '0000-00-00') { $due_date = date('m/d/Y', strtotime($due_date)); } else { $due_date = '--'; } $reminder_date = $entry['reminder']; //$reminder_date = $entry['reminder_date']; if (!empty($reminder_date) && $reminder_date != '0000-00-00 00:00:00') { $reminder_date = date('m/d/Y H:i', strtotime($reminder_date)); } else { $reminder_date = '--'; } foreach ($assignees as $assignee) { $assignees_string .= $assignee->getDisplayName() . ', '; } if (!empty($assignees_string)) { $assignees_string = substr($assignees_string, 0, -2); } else { $assignees_string = '--'; } //EOF:mod 20120816 $reminders_sent = array(); foreach ($assignees as $user) { //if ($user->getEmail()=='*****@*****.**'){ $reminder = new Reminder(); $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $task_obj->getId(), 'comment' => $comment)); //$reminder->setCreatedBy($this->logged_user); $save = $reminder->save(); if ($save && !is_error($save)) { $reminders_sent[] = $user->getDisplayName(); ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => 'AutoReminder', 'reminded_by_url' => '', 'object_name' => $task_obj->getName(), 'object_url' => $task_obj->getViewUrl(), 'object_type' => strtolower($task_obj->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'ticket_name' => $parent->getName(), 'ticket_url' => $parent->getViewUrl(), 'object_priority' => $priorities[(string) $task_obj->getPriority()], 'object_due_date' => $due_date, 'object_reminder_date_n_time' => $reminder_date, 'object_assignees' => $assignees_string, 'task_mark_complete_url' => $task_obj->getCompleteUrl() . '&auto=1', 'display_status_for_complete_url' => ''), $task_obj); } // if //} } // foreach } mysql_close($link); //EOF:mod }
/** * Render and process forgot password form * * @param void * @return null */ function forgot_password() { $forgot_password_data = $this->request->post('forgot_password'); $this->smarty->assign('forgot_password_data', $forgot_password_data); if ($this->request->isSubmitted()) { $errors = new ValidationErrors(); $email = trim(array_var($forgot_password_data, 'email')); if ($email == '') { $errors->addError(lang('Email address is required'), 'email'); } else { if (is_valid_email($email)) { $user = Users::findByEmail($email); if (instance_of($user, 'User')) { $user->setPasswordResetKey(make_string(13)); $user->setPasswordResetOn(new DateTimeValue()); $save = $user->save(); if (!$save || is_error($save)) { $errors->addError('Failed to update your user password with reset password data'); } // of } else { $errors->addError(lang('There is no user account that matches the e-mail address you entered'), 'email'); } // if } else { $errors->addError(lang('Invalid email address'), 'email'); } // if } // if if ($errors->hasErrors()) { $this->smarty->assign('errors', $errors); $this->render(); } // if $sent = ApplicationMailer::send(array($user), 'system/forgot_password', array('reset_url' => $user->getResetPasswordUrl())); $this->smarty->assign(array('success_message' => lang('We emailed reset password instructions at :email', array('email' => $user->getEmail())), 'forgot_password_data' => null)); } // if }
function register_assignees_flag($assignees_flag = array(), $is_new_object = false) { $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); if (!$is_new_object) { $query = "delete from healingcrystals_assignments_flag_fyi_actionrequest where object_id='" . $this->getId() . "'"; mysql_query($query, $link); } $users = array(); foreach ($assignees_flag['flag_fyi'] as $user_id) { if (!array_key_exists((string) $user_id, $users)) { $users[(string) $user_id] = array('flag_fyi' => '0', 'flag_actionrequest' => '0', 'priority_actionrequest' => '0', 'flag_email' => '0'); } $users[(string) $user_id]['flag_fyi'] = '1'; } foreach ($assignees_flag['flag_actionrequest'] as $user_id) { if (!array_key_exists((string) $user_id, $users)) { $users[(string) $user_id] = array('flag_fyi' => '0', 'flag_actionrequest' => '0', 'priority_actionrequest' => '0', 'flag_email' => '0'); } $users[(string) $user_id]['flag_actionrequest'] = '1'; } foreach ($assignees_flag['priority_actionrequest'] as $entry) { $vals = explode('_', $entry); list($temp_user_id, $priority) = $vals; if (array_key_exists((string) $temp_user_id, $users) && $users[(string) $temp_user_id]['flag_actionrequest'] == '1') { $users[(string) $temp_user_id]['priority_actionrequest'] = $priority; } } foreach ($assignees_flag['flag_email'] as $user_id) { if (!array_key_exists((string) $user_id, $users)) { $users[(string) $user_id] = array('flag_fyi' => '0', 'flag_actionrequest' => '0', 'priority_actionrequest' => '0', 'flag_email' => '0'); } $users[(string) $user_id]['flag_email'] = '1'; } foreach ($users as $user_id => $flags) { $query = "insert into healingcrystals_assignments_flag_fyi_actionrequest (user_id, object_id, flag_fyi, flag_actionrequest, priority_actionrequest, email_flag) values ('" . $user_id . "', '" . $this->getId() . "', '" . $flags['flag_fyi'] . "', '" . $flags['flag_actionrequest'] . "', '" . $flags['priority_actionrequest'] . "', '" . $flags['flag_email'] . "')"; //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($query) . "')"); mysql_query($query, $link); } //BOF:mod 20111011 #449 if ($is_new_object) { $query = "select user_id from healingcrystals_assignments_flag_fyi_actionrequest where object_id='" . $this->getId() . "' and email_flag='1'"; $result = mysql_query($query); $email_to = array(); if (mysql_num_rows($result)) { while ($entry = mysql_fetch_assoc($result)) { $email_to[] = new User($entry['user_id']); } } if (count($email_to)) { $owner_company = get_owner_company(); $project = $this->getProject(); // Prepare object type translations if (is_foreachable($languages)) { $object_type = array(); foreach ($languages as $language) { $object_type[$language->getLocale()] = $this->getVerboseType(false, $language); } // foreach } else { $object_type = $this->getVerboseType(); } // if $created_by_id = $this->getCreatedById(); $created_by = new User($created_by_id); $variables = array('details_body' => EmailTemplates::renderProjectObjectDetails($this, $languages), 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'object_type' => $object_type, 'object_name' => $this->getName(), 'object_body' => $this->getFormattedBody(), 'object_url' => $this->getViewUrl(), 'owner_company_name' => $owner_company->getName(), 'created_by_name' => $created_by->getDisplayName(), 'created_by_url' => $created_by->getViewUrl()); if ($context === null) { $context = $this->getNotificationContext(); } // if ApplicationMailer::send($email_to, 'resources/task_assigned', $variables, $context); } } //EOF:mod 20111011 #449 mysql_close($link); }
/** * Create a new reminder * * @param void * @return null */ function add() { $this->wireframe->print_button = false; $parent = ProjectObjects::findById($this->request->getId('parent_id')); if (!instance_of($parent, 'ProjectObject')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $project = $parent->getProject(); if (!instance_of($project, 'Project')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $assignees = $parent->getAssignees(); $subscribers = $parent->getSubscribers(); $commenters = Comments::findCommenters($parent, $this->logged_user); $reminder_data = $this->request->post('reminder'); if (!is_array($reminder_data)) { $who = 'user'; if (is_foreachable($assignees)) { $who = 'assignees'; } elseif (is_foreachable($subscribers)) { $who = 'subscribers'; } elseif (is_foreachable($commenters)) { $who = 'commenters'; } // if $reminder_data = array('who' => $who); } // if $this->smarty->assign(array('parent' => $parent, 'assignees' => $assignees, 'subscribers' => $subscribers, 'commenters' => $commenters, 'project_users' => ProjectUsers::findUserIdsByProject($project), 'reminder_data' => $reminder_data)); if ($this->request->isSubmitted()) { $send_to_users = null; switch ($reminder_data['who']) { case 'assignees': $send_to_users = $assignees; break; case 'subscribers': $send_to_users = $subscribers; break; case 'commenters': $send_to_users = $commenters; break; case 'user': $user_id = (int) array_var($reminder_data, 'user_id'); if ($user_id) { $user = Users::findById($user_id); if (instance_of($user, 'User')) { $send_to_users = array($user); } // if } // if break; } // switch // Do reminder if (is_foreachable($send_to_users)) { $comment = trim(array_var($reminder_data, 'comment')); if ($comment) { require_once SMARTY_PATH . '/plugins/modifier.clickable.php'; require_once ANGIE_PATH . '/classes/htmlpurifier/init.php'; $comment = strip_tags(prepare_html($comment, true)); // make sure we have clean text $comment = nl2br(smarty_modifier_clickable($comment)); // preserve breaklines and convert links } // if db_begin_work(); $reminders_sent = array(); foreach ($send_to_users as $user) { $reminder = new Reminder(); $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $parent->getId(), 'comment' => $comment)); $reminder->setCreatedBy($this->logged_user); $save = $reminder->save(); if ($save && !is_error($save)) { $reminders_sent[] = $user->getDisplayName(); ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => $this->logged_user->getDisplayName(), 'reminded_by_url' => $this->logged_user->getViewUrl(), 'object_name' => $parent->getName(), 'object_url' => $parent->getViewUrl(), 'object_type' => strtolower($parent->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl()), $parent); } // if } // foreach db_commit(); $message = lang('Users reminded: :users', array('users' => implode(', ', $reminders_sent))); if ($this->request->get('skip_layout')) { $this->renderText($message); } else { flash_success($message); $this->redirectToUrl($parent->getViewUrl()); } // if // No reminders } else { if ($this->request->get('skip_layout')) { $this->renderText(lang('0 users reminded')); } else { flash_success('0 users reminded'); $this->redirectToUrl($parent->getViewUrl()); } // if } // if } // if }
protected function afterDeliver() { parent::afterDeliver(); }
/** * Upload file document page action * * @param void * @return void */ function upload_file() { $this->wireframe->print_button = false; if (!Document::canAdd($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $file = $_FILES['file']; $file_data = $this->request->post('file'); if (!is_array($file_data)) { $file_data = array('category_id' => $this->active_document_category->getId()); } // if require_once SMARTY_PATH . '/plugins/modifier.filesize.php'; $this->smarty->assign(array('file_data' => $file_data, 'max_upload_size' => smarty_modifier_filesize(get_max_upload_size()))); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_document->setAttributes($file_data); if (is_array($file)) { $destination_file = get_available_uploads_filename(); if (move_uploaded_file($file['tmp_name'], $destination_file)) { if (FIX_UPLOAD_PERMISSION !== false) { @chmod($destination_file, FIX_UPLOAD_PERMISSION); } // if $this->active_document->setName($file['name']); $this->active_document->setBody(basename($destination_file)); $this->active_document->setMimeType($file['type']); } // if } // if $this->active_document->setCreatedBy($this->logged_user); $this->active_document->setType('file'); $save = $this->active_document->save(); if ($save && !is_error($save)) { $notify_user_ids = $this->request->post('notify_users'); if (is_foreachable($notify_user_ids)) { $notify_users = Users::findByIds($notify_user_ids); $owner_company = get_owner_company(); if (is_foreachable($notify_users)) { ApplicationMailer::send($notify_users, 'documents/new_upload_file_document', array('document_name' => $this->active_document->getName(), 'created_by_name' => $this->active_document->getCreatedByName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'document_url' => $this->active_document->getViewUrl(), 'owner_company_name' => $owner_company->getName()), $this->active_document); } // if } // if db_commit(); flash_success('Document ":document_name" has been uploaded', array('document_name' => $this->active_document->getName())); $this->redirectTo('documents'); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } // if }
/** * Change invoice status to CANCELED * * @param void * @return null */ function cancel() { if ($this->active_invoice->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_invoice->canCancel($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->request->isSubmitted()) { db_begin_work(); $this->active_invoice->setStatus(INVOICE_STATUS_CANCELED, $this->logged_user, new DateTimeValue()); $save = $this->active_invoice->save(); if ($save && !is_error($save)) { db_commit(); $issued_to_user = $this->active_invoice->getIssuedTo(); if (instance_of($issued_to_user, 'User')) { $notify_users = array($issued_to_user); if ($issued_to_user->getId() != $this->logged_user->getId()) { $notify_users[] = $this->logged_user; } // if ApplicationMailer::send($notify_users, 'invoicing/cancel', array('closed_by_name' => $this->logged_user->getDisplayName(), 'closed_by_url' => $this->logged_user->getViewUrl(), 'invoice_number' => $this->active_invoice->getNumber(), 'invoice_url' => $this->active_invoice->getCompanyViewUrl())); } // if flash_success('Invoice #:number has been canceled', array('number' => $this->active_invoice->getName($short))); } else { db_rollback(); flash_error('Failed to cancel invoice #:number', array('number' => $this->active_invoice->getName($short))); } // if $this->redirectToUrl($this->active_invoice->getViewUrl()); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
/** * Send welcome message * * @param void * @return null */ function send_welcome_message() { if ($this->active_user->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_user->canSendWelcomeMessage($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $this->skip_layout = $this->request->isAsyncCall(); $welcome_message_data = $this->request->post('welcome_message'); if (!is_array($welcome_message_data)) { $welcome_message_data = array('message' => UserConfigOptions::getValue('welcome_message', $this->active_user)); } // if $this->smarty->assign('welcome_message_data', $welcome_message_data); if ($this->request->isSubmitted()) { $welcome_message = trim(array_var($welcome_message_data, 'message')); if ($welcome_message) { UserConfigOptions::setValue('welcome_message', $welcome_message, $this->active_user); } else { UserConfigOptions::removeValue('welcome_message', $this->active_user); } // if $password = make_password(11); $this->active_user->setPassword($password); $save = $this->active_user->save(); if ($save && !is_error($save)) { $welcome_message_sent = ApplicationMailer::send(array($this->active_user), 'system/new_user', array('created_by_id' => $this->logged_user->getId(), 'created_by_name' => $this->logged_user->getDisplayName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'email' => $this->active_user->getEmail(), 'password' => $password, 'login_url' => assemble_url('login'), 'welcome_body' => $welcome_message ? nl2br(clean($welcome_message)) : '')); if ($welcome_message_sent) { $message = lang('Welcome message has been sent to :name', array('name' => $this->active_user->getDisplayName())); } else { $message = lang('Failed to send welcome message to :name. Please try again later', array('name' => $this->active_user->getDisplayName())); } // if if ($this->request->isAsyncCall()) { die($message); } else { flash_success($message); $this->redirectToUrl($this->active_user->getViewUrl()); } // if } else { if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED); } else { flash_error($message); $this->redirectToUrl($this->active_user->getViewUrl()); } // if } // if } // if }
/** * Mass mailer * * @param void * @return null */ function mass_mailer() { if (!MASS_MAILER_ENABLED) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $email_data = $this->request->post('email'); $this->smarty->assign(array('email_data' => $email_data, 'exclude' => array($this->logged_user->getId()))); if ($this->request->isSubmitted()) { $errors = new ValidationErrors(); $subject = trim(array_var($email_data, 'subject')); $body = trim(array_var($email_data, 'body')); $recipient_ids = array_var($email_data, 'recipients'); if (empty($subject)) { $errors->addError(lang('Subject is required'), 'subject'); } // if if (empty($body)) { $errors->addError(lang('Body is required'), 'body'); } // if $recipients = array(); if (is_foreachable($recipient_ids)) { $recipients = Users::findByIds(array_unique($recipient_ids)); } // if if (!is_foreachable($recipients)) { $errors->addError(lang('Please select recipients'), 'recipients'); } // if if ($errors->hasErrors()) { $this->smarty->assign('errors', $errors); $this->render(); } // if $mailer =& ApplicationMailer::mailer(); $message = new Swift_Message($subject, $body, 'text/html', EMAIL_ENCODING, EMAIL_CHARSET); $recipients_list = new Swift_RecipientList(); foreach ($recipients as $recipient) { $name = $recipient->getDisplayName(); $email = $recipient->getEmail(); if ($name == $email) { $name = ''; } // if $recipients_list->add($email, $name); } // foreach $name = $this->logged_user->getDisplayName(); $email = $this->logged_user->getEmail(); if ($name == $email) { $name = ''; } // if if ($mailer->batchSend($message, $recipients_list, new Swift_Address($email, $name))) { flash_success('Email has been successfully sent'); } else { flash_error('Failed to send email'); } // if $this->redirectTo('admin_tools_mass_mailer'); } // if }
/** * Save this payment * * @param void * @return null */ function save() { db_begin_work(); $invoice = $this->getInvoice(); if (!instance_of($invoice, 'Invoice')) { return new Error('$invoice is not valid instance of Invoice class', true); } // if $save = parent::save(); if ($save && !is_error($save)) { if ($invoice->getMaxPayment(false) == 0 && $invoice->isIssued()) { $invoice->setStatus(INVOICE_STATUS_BILLED, get_logged_user(), $this->getPaidOn()); $save = $invoice->save(); if ($save && !is_error($save)) { $logged_user = get_logged_user(); if ($this->send_notification) { $issued_to_user = $invoice->getIssuedTo(); if (instance_of($issued_to_user, 'User')) { $notify_users = array($logged_user); if ($issued_to_user->getId() != $logged_user->getId()) { $notify_users[] = $issued_to_user; } // if ApplicationMailer::send($notify_users, 'invoicing/billed', array('closed_by_name' => $logged_user->getDisplayName(), 'closed_by_url' => $logged_user->getViewUrl(), 'invoice_number' => $invoice->getNumber(), 'invoice_url' => $invoice->getCompanyViewUrl())); } // if } // if db_commit(); return true; } else { db_rollback(); return $save; } // if } // if db_commit(); return true; } else { db_rollback(); return $save; } // if }
/** * Create new comment * * @param void * @return null */ function add() { $this->wireframe->print_button = false; $active_object = ProjectObjects::findById($this->request->getId('parent_id')); if (!instance_of($active_object, 'ProjectObject')) { $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall()); } // if if (!$active_object->canComment($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall()); } // if $active_object->prepareProjectSectionBreadcrumb($this->wireframe); $this->wireframe->addBreadCrumb($active_object->getName(), $active_object->getViewUrl()); if (!$active_object->canComment($this->logged_user)) { if ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_FORBIDDEN, null, true, true); } else { flash_error('Parent object not found'); $this->redirectToReferer($this->active_project->getOverviewUrl()); } // if } // if $comment_data = $this->request->post('comment'); $this->smarty->assign(array('active_object' => $active_object, 'page_tab' => $active_object->getProjectTab(), 'comment_data' => $comment_data, 'recent_comments' => Comments::findRecentObject($active_object, 5, STATE_VISIBLE, $this->logged_user->getVisibility()))); if ($this->request->isSubmitted()) { db_begin_work(); $complete_parent_object = (bool) array_var($comment_data, 'complete_parent_object'); $this->active_comment = new Comment(); $this->active_comment->log_activities = false; if ($complete_parent_object) { $this->active_comment->send_notification = false; } // if attach_from_files($this->active_comment, $this->logged_user); $this->active_comment->setAttributes($comment_data); $this->active_comment->setParent($active_object); $this->active_comment->setProjectId($this->active_project->getId()); $this->active_comment->setState(STATE_VISIBLE); $this->active_comment->setVisibility($active_object->getVisibility()); if (trim($this->active_comment->getCreatedByName()) == '' || trim($this->active_comment->getCreatedByEmail()) == '') { $this->active_comment->setCreatedBy($this->logged_user); } // if $save = $this->active_comment->save(); if ($save && !is_error($save)) { $active_object->subscribe($this->logged_user); $activity = new NewCommentActivityLog(); $activity->log($this->active_comment, $this->logged_user); if ($complete_parent_object && $active_object->canChangeCompleteStatus($this->logged_user)) { $active_object->complete($this->logged_user, $this->active_comment->getFormattedBody(true)); } // if db_commit(); $this->active_comment->ready(); //BOF: mod $subscribers_to_notify = array_var($comment_data, 'subscribers_to_notify'); $action_request_user_id = array_var($comment_data, 'action_request'); //$priority_actionrequest = array_var($comment_data, 'priority_actionrequest'); //BOF:mod 20110517 if ($complete_parent_object) { $subscribers_to_notify = array(); $action_request_user_id = array(); } //EOF:mod 20110517 //BOF:mod 20110719 /* //EOF:mod 20110719 if (!empty($action_request_user_id)){ $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); foreach ($action_request_user_id as $id){ $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'"; $result = mysql_query($query); if (mysql_num_rows($result)){ $query = "update healingcrystals_assignments_action_request set is_action_request='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'"; mysql_query($query); } else { $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added) values ('" . $id . "', '1', '0', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())"; mysql_query($query); } } foreach($priority_actionrequest as $val){ $temp = explode('_', $val); list($temp_user_id, $priority) = $temp; if (in_array($temp_user_id, $action_request_user_id)){ $query = "update healingcrystals_assignments_action_request set priority_actionrequest='" . $priority . "' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $temp_user_id . "'"; mysql_query($query); } } mysql_close($link); } //BOF:mod 20110719 */ //EOF:mod 20110719 //BOF:mod 20110719 //$action_request_user_id = array(); //if (!empty($priority_actionrequest)){ $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); if (!empty($action_request_user_id)) { //foreach($priority_actionrequest as $val){ foreach ($action_request_user_id as $val) { //$temp = explode('_', $val); //list($temp_user_id, $priority) = $temp; $temp_user_id = $val; $priority = '0'; //if ((int)$priority>-10){ $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $temp_user_id . "'"; $result = mysql_query($query, $link); if (mysql_num_rows($result)) { $query1 = "update healingcrystals_assignments_action_request set is_action_request='1', priority_actionrequest='" . $priority . "' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $temp_user_id . "'"; mysql_query($query1, $link); } else { $query1 = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added, priority_actionrequest) values ('" . $temp_user_id . "', '1', '0', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now(), '" . $priority . "')"; mysql_query($query1, $link); } //$action_request_user_id[] = $temp_user_id; $task = new Task(); $task->setProjectId(TASK_LIST_PROJECT_ID); $task->setParentId(Page::getTaskPageIdForUser($val)); $task->setParentType('Page'); $task->setCreatedBy($this->logged_user); $task->setVisibility(VISIBILITY_NORMAL); $task->setState(STATE_VISIBLE); $task_body = ''; $parent = $this->active_comment->getParent(); $url = $parent->getViewUrl() . '#comment' . $this->active_comment->getId(); $comment_body = $this->active_comment->getBody(); $comment_body = strip_tags($comment_body); //$task_body = substr($comment_body, 0, 10) . '.. <br/><a href="' . $url . '">View Task in Full</a>'; if (strlen($comment_body) > 525) { $task_body .= substr($comment_body, 0, 525) . '..'; } else { $task_body .= $comment_body; } $task_body .= '<br/><a href="' . $url . '">View Task in Full</a>'; $attachments = $this->active_comment->getAttachments(); if (is_foreachable($attachments)) { $task_body .= '<br/>Attachments:<br/>'; foreach ($attachments as $attachment) { $task_body .= '<a href="' . $attachment->getViewUrl() . '">' . $attachment->getName() . '</a><br/>'; } } $task->setBody($task_body); $savetask = $task->save(); if ($savetask && !is_error($savetask)) { $task->ready(); mysql_query("insert into actionrequests_to_tasklist (comment_id, user_id, type, object_id) values ('" . $this->active_comment->getId() . "', '" . $temp_user_id . "', 'Task', '" . $task->getId() . "')"); } //} } } //EOF:mod 20110719 if (!empty($subscribers_to_notify)) { //BOF:task_1260 /* //EOF:task_1260 mysql_query("update healingcrystals_assignments_action_request set is_fyi='0' where object_id='" . $active_object->getId() . "'"); if (!empty($subscribers_to_notify)){ $temp = $subscribers_to_notify; foreach($temp as $id){ $query = "select * from healingcrystals_assignments_action_request where object_id='" . $active_object->getId() . "' and user_id='" . $id . "'"; $result = mysql_query($query, $link); if (mysql_num_rows($result)){ mysql_query("update healingcrystals_assignments_action_request set is_fyi='1' where user_id='" . $id . "' and object_id='" . $active_object->getId() . "'"); } else { mysql_query("insert into healingcrystals_assignments_action_request (user_id, object_id, is_fyi) values ('" . $id . "', '" . $active_object->getId() . "', '1')"); } } } mysql_query("delete from healingcrystals_assignments_action_request where object_id='" . $active_object->getId() . "' and is_action_request='0' and is_fyi='0'"); //BOF:task_1260 */ foreach ($subscribers_to_notify as $id) { $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $query = "update healingcrystals_assignments_action_request set is_fyi='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'"; mysql_query($query); } else { $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added) values ('" . $id . "', '0', '1', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())"; mysql_query($query); } } //EOF:task_1260 } //shawn wants to fire emails for only action request users and not for FYI users // for this, $subscribers_to_notify is set to $action_request_user_id, which will // take care of any assignments that were made above the code : 22-MAR-2011 //BOF:mod 20110623 $fyi_users = $subscribers_to_notify; $fyi_to = ''; //EOF:mod 20110623 $subscribers_to_notify = $action_request_user_id; //BOF:mod $email_to_user_ids = array_var($comment_data, 'email'); $emailed_to = ''; foreach ($email_to_user_ids as $user_id) { $temp_user = new User($user_id); //BOF:mod 20130429 /* //EOF:mod 20130429 $emailed_to .= $temp_user->getName() . ', '; //BOF:mod 20130429 */ //EOF:mod 20130429 $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $user_id . "'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $query = "update healingcrystals_assignments_action_request set marked_for_email='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $user_id . "'"; mysql_query($query); } else { $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, marked_for_email, selected_by_user_id, comment_id, date_added) values ('" . $user_id . "', '0', '0', '1', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())"; mysql_query($query); } } reset($email_to_user_ids); //EOF:mod if (!empty($subscribers_to_notify)) { //$subscribers_to_notify = implode(',', $subscribers_to_notify); //mysql_query("insert into healingcrystals_testing (query, fired_at) values ('" . $subscribers_to_notify . "', now())"); $notified_to = ''; //$subscribers = explode(',', $subscribers_to_notify); $subscribers = $subscribers_to_notify; $all_subscribers = $active_object->getSubscribers(); $excluded = array(); $included = array(); //$excluded_temp = array(); //$included_temp = array(); $subscribers_name = ''; foreach ($all_subscribers as $reg_subscriber) { $subscribers_name .= $reg_subscriber->getName() . "<br/>"; $subscriber_excluded = true; //if ($this->logged_user->getId()!=$reg_subscriber->getId()){ foreach ($subscribers as $subscriber_id) { $subscriber_id = trim($subscriber_id); if ($reg_subscriber->getId() == $subscriber_id) { $included[] = $reg_subscriber; //BOF:mod 20130429 /* //EOF:mod 20130429 $notified_to .= $reg_subscriber->getName() . ', '; //BOF:mod 20130429 */ //EOF:mod 20130429 //$included_temp[] = $reg_subscriber->getId(); $subscriber_excluded = false; //$subscribers_name .= $reg_subscriber->getName() . "<br/>"; break; } } //BOF:mod 20110623 foreach ($fyi_users as $fyi_user_id) { $fyi_user_id = trim($fyi_user_id); if ($reg_subscriber->getId() == $fyi_user_id) { //BOF:mod 20130429 /* //EOF:mod 20130429 $fyi_to .= $reg_subscriber->getName() . ', '; //BOF:mod 20130429 */ //EOF:mod 20130429 break; } } //EOF:mod 20110623 //} if ($subscriber_excluded) { $excluded[] = $reg_subscriber->getId(); //$excluded_temp[] = $reg_subscriber->getId(); } } //$link = mysql_connect(DB_HOST, DB_USER, DB_PASS); //mysql_select_db(DB_NAME); //mysql_query("insert into healingcrystals_testing (query, fired_at) values ('" . implode('|', $included_temp) . ' = ' . implode('|', $excluded_temp) . "', now())"); //mysql_close($link); //BOF:mod 20110517 //if (count($included)){ if (!$complete_parent_object && count($included)) { //EOF:mod 20110517 //BOF:mod 20110623 //$notified_to = '<br/><br/>Notification emailed to: ' . substr($notified_to, 0, -2); //$this->active_comment->setBody($this->active_comment->getBody() . $notified_to . $fyi_to); //BOF:mod 20130429 /* //EOF:mod 20130429 if (!empty($notified_to)){ $notified_to = '<br/><br/>Action Request marked to: ' . substr($notified_to, 0, -2); } if (!empty($fyi_to)){ $fyi_to = (empty($notified_to) ? '<br/><br/>' : '<br/>') . 'FYI Comment marked to: ' . substr($fyi_to, 0, -2); } if (!empty($emailed_to)){ $emailed_to = (empty($notified_to) && empty($fyi_to) ? '<br/><br/>' : '<br/>') . 'Email sent to: ' . substr($emailed_to, 0, -2); } $this->active_comment->setBody($this->active_comment->getBody() . $notified_to . $fyi_to . $emailed_to); //EOF:mod 20110623 $this->active_comment->save(); //BOF:mod 20130429 */ //EOF:mod 20130429 //BOF:mod 20110720 ticketid246 /* //EOF:mod 20110720 ticketid246 $created_by = $this->active_comment->getCreatedBy(); $parent = $active_object; $parent->sendToSubscribers('resources/new_comment', array( 'comment_body' => $this->active_comment->getFormattedBody(), 'comment_url' => $this->active_comment->getViewUrl(), 'created_by_url' => $created_by->getViewUrl(), 'created_by_name' => $created_by->getDisplayName(), 'subscribers_name' => "<br/><br/>-- SET NOTIFICATIONS --<br/>" . $subscribers_name . "<br/><br/>", 'comment_id' => $this->active_comment->getId(), ), $excluded, $parent); //BOF:mod 20110720 ticketid246 */ //EOF:mod 20110720 ticketid246 /*$created_by = $this->active_comment->getCreatedBy(); $variables = array('owner_company_name' => get_owner_company(), 'project_name' => $this->active_project->getName(), 'project_url' => $this->active_project->getOverviewUrl(), 'object_type' => $this->active_comment->getVerboseType(), 'object_name' => $this->active_comment->getName(), 'comment_body' => $this->active_comment->getFormattedBody(), 'comment_url' => $this->active_comment->getViewUrl(), 'created_by_url' => $created_by->getViewUrl(), 'created_by_name' => $created_by->getDisplayName(),); ApplicationMailer::send($users, 'resources/new_comment', $variables, $this->active_milestone);*/ } } elseif (!empty($fyi_users)) { $all_subscribers = $active_object->getSubscribers(); foreach ($all_subscribers as $reg_subscriber) { foreach ($fyi_users as $fyi_user_id) { $fyi_user_id = trim($fyi_user_id); if ($reg_subscriber->getId() == $fyi_user_id) { $fyi_to .= $reg_subscriber->getName() . ', '; break; } } } /*$fyi_to = '<br/><br/>FYI Comment marked to: ' . substr($fyi_to, 0, -2); if (!empty($emailed_to)){ $emailed_to = (empty($fyi_to) ? '<br/><br/>' : '<br/>') . 'Email sent to: ' . substr($emailed_to, 0, -2); } $this->active_comment->setBody($this->active_comment->getBody() . $fyi_to . $emailed_to); $this->active_comment->save();*/ } elseif (!empty($email_to_user_ids)) { /*$emailed_to = '<br/><br/>Email sent to: ' . substr($emailed_to, 0, -2); $this->active_comment->setBody($this->active_comment->getBody() . $emailed_to); $this->active_comment->save();*/ } if (count($email_to_user_ids)) { $users = array(); foreach ($email_to_user_ids as $user_id) { if ($user_id != $this->logged_user->getId()) { $users[] = new User($user_id); } } $created_by = $this->active_comment->getCreatedBy(); $variables = array('owner_company_name' => get_owner_company(), 'project_name' => $this->active_project->getName(), 'project_url' => $this->active_project->getOverviewUrl(), 'object_type' => $this->active_comment->getVerboseType(), 'object_name' => $this->active_comment->getName(), 'object_body' => $this->active_comment->getFormattedBody(), 'object_url' => $this->active_comment->getViewUrl(), 'comment_body' => $this->active_comment->getFormattedBody(), 'comment_url' => $this->active_comment->getViewUrl(), 'created_by_url' => $created_by->getViewUrl(), 'created_by_name' => $created_by->getDisplayName(), 'details_body' => '', 'comment_id' => $this->active_comment->getId()); //BOF:mod 20111101 /* //EOF:mod 20111101 ApplicationMailer::send($users, 'resources/new_comment', $variables, $this->active_milestone); //BOF:mod 20111101 */ $parent_id = $this->active_comment->getParentId(); $parent_type = $this->active_comment->getParentType(); $parent_obj = new $parent_type($parent_id); $attachments = null; $object_attachments = $this->active_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($users, 'resources/new_comment', $variables, $parent_obj, $attachments); //EOF:mod 20111101 } //BOF:mod 20121030 $modify_comments_sorting = false; $reply_to_comment_id = $this->request->post('reply_to_comment_id'); if (!empty($reply_to_comment_id)) { $sql_data = array('integer_field_2' => $reply_to_comment_id); Comments::update($sql_data, "id='" . $this->active_comment->getId() . "'", TABLE_PREFIX . 'project_objects'); //$modify_comments_sorting = true; } //$count = 0; /*$link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $sql = "select * from " . TABLE_PREFIX . "project_objects where parent_id='" . $this->active_comment->getParentId() . "' and parent_type='" . $this->active_comment->getParentType() . "' and type='Comment' and (position is null or position='0')"; $result = mysql_query($sql, $link); if (!mysql_num_rows($result) ){ $sql = "select max(position) as count from " . TABLE_PREFIX . "project_objects where parent_id='" . $this->active_comment->getParentId() . "' and parent_type='" . $this->active_comment->getParentType() . "' and type='Comment'"; $result = mysql_query($sql, $link); $info = mysql_fetch_assoc($result); $count = $info['count']; $sql_data = array('position' => ++$count); Comments::update($sql_data, "id='" . $this->active_comment->getId() . "'", TABLE_PREFIX . 'project_objects'); } else { $modify_comments_sorting = true; } mysql_close($link);*/ //if ($modify_comments_sorting) $this->modify_comments_sorting($count); //EOF:mod 20121030 if ($this->request->isApiCall()) { $this->serveData($this->active_comment, 'comment'); } else { flash_success('Comment successfully posted'); //$this->redirectToUrl($this->active_comment->getRealViewUrl()); $this->redirectToUrl($this->active_comment->getParent()->getViewUrl()); } // if } else { db_rollback(); if ($this->request->isApiCall()) { $this->serveData($save); } else { $this->smarty->assign('errors', $save); } // if } // if } else { if ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true); } // if } // if }
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; }