status) ) {
$this->status = $this->getDefaultStatus();
}
return parent::save($check_notify);
}
function get_summary_text()
{
return "$this->name";
}
function create_export_query(&$order_by, &$where, $relate_link_join='')
{
$custom_join = $this->custom_fields->getJOIN(true, true,$where);
if($custom_join)
$custom_join['join'] .= $relate_link_join;
$contact_required = stristr($where,"contacts");
if($contact_required)
{
$query = "SELECT tasks.*, contacts.first_name, contacts.last_name, users.user_name as assigned_user_name ";
if($custom_join){
$query .= $custom_join['select'];
}
$query .= " FROM contacts, tasks ";
$where_auto = "tasks.contact_id = contacts.id AND tasks.deleted=0 AND contacts.deleted=0";
}
else
{
$query = 'SELECT tasks.*, users.user_name as assigned_user_name ';
if($custom_join){
$query .= $custom_join['select'];
}
$query .= ' FROM tasks ';
$where_auto = "tasks.deleted=0";
}
if($custom_join){
$query .= $custom_join['join'];
}
$query .= " LEFT JOIN users ON tasks.assigned_user_id=users.id ";
if($where != "")
$query .= "where $where AND ".$where_auto;
else
$query .= "where ".$where_auto;
if($order_by != "")
$query .= " ORDER BY ". $this->process_order_by($order_by, null);
else
$query .= " ORDER BY tasks.name";
return $query;
}
function fill_in_additional_list_fields()
{
}
function fill_in_additional_detail_fields()
{
parent::fill_in_additional_detail_fields();
global $app_strings;
if (isset($this->contact_id)) {
$contact = new Contact();
$contact->retrieve($this->contact_id);
if($contact->id != "") {
$this->contact_name = $contact->full_name;
$this->contact_name_owner = $contact->assigned_user_id;
$this->contact_name_mod = 'Contacts';
$this->contact_phone = $contact->phone_work;
$this->contact_email = $contact->emailAddress->getPrimaryAddress($contact);
} else {
$this->contact_name_mod = '';
$this->contact_name_owner = '';
$this->contact_name='';
$this->contact_email = '';
$this->contact_id='';
}
}
$this->fill_in_additional_parent_fields();
}
function fill_in_additional_parent_fields()
{
$this->parent_name = '';
global $app_strings, $beanFiles, $beanList, $locale;
if ( ! isset($beanList[$this->parent_type]))
{
$this->parent_name = '';
return;
}
$beanType = $beanList[$this->parent_type];
require_once($beanFiles[$beanType]);
$parent = new $beanType();
if (is_subclass_of($parent, 'Person')) {
$query = "SELECT first_name, last_name, assigned_user_id parent_name_owner from $parent->table_name where id = '$this->parent_id'";
}
else if (is_subclass_of($parent, 'File')) {
$query = "SELECT document_name, assigned_user_id parent_name_owner from $parent->table_name where id = '$this->parent_id'";
}
else {
$query = "SELECT name ";
if(isset($parent->field_defs['assigned_user_id'])){
$query .= " , assigned_user_id parent_name_owner ";
}else{
$query .= " , created_by parent_name_owner ";
}
$query .= " from $parent->table_name where id = '$this->parent_id'";
}
$result = $this->db->query($query,true," Error filling in additional detail fields: ");
// Get the id and the name.
$row = $this->db->fetchByAssoc($result);
if ($row && !empty($row['parent_name_owner'])){
$this->parent_name_owner = $row['parent_name_owner'];
$this->parent_name_mod = $this->parent_type;
}
if (is_subclass_of($parent, 'Person') and $row != null)
{
$this->parent_name = $locale->getLocaleFormattedName(stripslashes($row['first_name']), stripslashes($row['last_name']));
}
else if (is_subclass_of($parent, 'File') && $row != null) {
$this->parent_name = $row['document_name'];
}
elseif($row != null)
{
$this->parent_name = stripslashes($row['name']);
}
else {
$this->parent_name = '';
}
}
protected function formatStartAndDueDates(&$task_fields, $dbtime, $override_date_for_subpanel)
{
global $timedate;
if(empty($dbtime)) return;
$today = $timedate->nowDbDate();
$task_fields['TIME_DUE'] = $timedate->to_display_time($dbtime);
$task_fields['DATE_DUE'] = $timedate->to_display_date($dbtime);
$date_due = $task_fields['DATE_DUE'];
$dd = $timedate->to_db_date($date_due, false);
$taskClass = 'futureTask';
if ($dd < $today){
$taskClass = 'overdueTask';
}else if( $dd == $today ){
$taskClass = 'todaysTask';
}
$task_fields['DATE_DUE']= "$date_due";
if($override_date_for_subpanel){
$task_fields['DATE_START']= "$date_due";
}
}
function get_list_view_data(){
global $action, $currentModule, $focus, $current_module_strings, $app_list_strings, $timedate;
$override_date_for_subpanel = false;
if(!empty($_REQUEST['module']) && $_REQUEST['module'] !='Calendar' && $_REQUEST['module'] !='Tasks' && $_REQUEST['module'] !='Home'){
//this is a subpanel list view, so override the due date with start date so that collections subpanel works as expected
$override_date_for_subpanel = true;
}
$today = $timedate->nowDb();
$task_fields = $this->get_list_view_array();
$dbtime = $timedate->to_db($task_fields['DATE_DUE']);
if($override_date_for_subpanel){
$dbtime = $timedate->to_db($task_fields['DATE_START']);
}
if(!empty($dbtime))
{
$task_fields['TIME_DUE'] = $timedate->to_display_time($dbtime);
$task_fields['DATE_DUE'] = $timedate->to_display_date($dbtime);
$this->formatStartAndDueDates($task_fields, $dbtime, $override_date_for_subpanel);
}
if (!empty($this->priority))
$task_fields['PRIORITY'] = $app_list_strings['task_priority_dom'][$this->priority];
if (isset($this->parent_type))
$task_fields['PARENT_MODULE'] = $this->parent_type;
if ($this->status != "Completed" && $this->status != "Deferred" )
{
$setCompleteUrl = "";
$task_fields['SET_COMPLETE'] = $setCompleteUrl . SugarThemeRegistry::current()->getImage("close_inline","title=".translate('LBL_LIST_CLOSE','Tasks')." border='0'",null,null,'.gif',translate('LBL_LIST_CLOSE','Tasks'))."";
}
// make sure we grab the localized version of the contact name, if a contact is provided
if (!empty($this->contact_id))
{
$contact_temp = BeanFactory::getBean("Contacts", $this->contact_id);
if (!empty($contact_temp))
{
// Make first name, last name, salutation and title of Contacts respect field level ACLs
$contact_temp->_create_proper_name_field();
$this->contact_name = $contact_temp->full_name;
$this->contact_phone = $contact_temp->phone_work;
}
}
$task_fields['CONTACT_NAME']= $this->contact_name;
$task_fields['CONTACT_PHONE']= $this->contact_phone;
$task_fields['TITLE'] = '';
if (!empty($task_fields['CONTACT_NAME'])) {
$task_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$task_fields['CONTACT_NAME'];
}
if (!empty($this->parent_name)) {
$task_fields['TITLE'] .= "\n".$app_list_strings['parent_type_display'][$this->parent_type].": ".$this->parent_name;
$task_fields['PARENT_NAME']=$this->parent_name;
}
return $task_fields;
}
function set_notification_body($xtpl, $task)
{
global $app_list_strings;
global $timedate;
$notifyUser = $task->current_notify_user;
$prefDate = $notifyUser->getUserDateTimePreferences();
$xtpl->assign("TASK_SUBJECT", $task->name);
//MFH #13507
$xtpl->assign("TASK_PRIORITY", (isset($task->priority)?$app_list_strings['task_priority_dom'][$task->priority]:""));
if(!empty($task->date_due))
{
$duedate = $timedate->fromDb($task->date_due);
$xtpl->assign("TASK_DUEDATE", $timedate->asUser($duedate, $notifyUser)." ".TimeDate::userTimezoneSuffix($duedate, $notifyUser));
} else {
$xtpl->assign("TASK_DUEDATE", '');
}
$xtpl->assign("TASK_STATUS", (isset($task->status)?$app_list_strings['task_status_dom'][$task->status]:""));
$xtpl->assign("TASK_DESCRIPTION", $task->description);
return $xtpl;
}
function bean_implements($interface){
switch($interface){
case 'ACL':return true;
}
return false;
}
function listviewACLHelper(){
$array_assign = parent::listviewACLHelper();
$is_owner = false;
if(!empty($this->parent_name)){
if(!empty($this->parent_name_owner)){
global $current_user;
$is_owner = $current_user->id == $this->parent_name_owner;
}
}
if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)){
$array_assign['PARENT'] = 'a';
}else{
$array_assign['PARENT'] = 'span';
}
$is_owner = false;
if(!empty($this->contact_name)){
if(!empty($this->contact_name_owner)){
global $current_user;
$is_owner = $current_user->id == $this->contact_name_owner;
}
}
if( ACLController::checkAccess('Contacts', 'view', $is_owner)){
$array_assign['CONTACT'] = 'a';
}else{
$array_assign['CONTACT'] = 'span';
}
return $array_assign;
}
public function getDefaultStatus()
{
$def = $this->field_defs['status'];
if (isset($def['default'])) {
return $def['default'];
} else {
$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 '';
}
}