filename, "."); $file_ext = ""; //get file extension if ($file_ext_beg > 0) { $file_ext = substr($this->filename, $file_ext_beg + 1); } //check to see if this is a file with extension located in "badext" foreach ($sugar_config['upload_badext'] as $badExt) { if (strtolower($file_ext) == strtolower($badExt)) { //if found, then append with .txt and break out of lookup $this->name = $this->name . ".txt"; $this->file_mime_type = 'text/'; $this->filename = $this->filename . ".txt"; break; // no need to look for more } } } /** * overrides SugarBean's method. * If a system setting is set, it will mark all related ecmprivatedocuments as deleted, and attempt to delete files that are * related to those ecmprivatedocuments * @param string id ID */ function mark_deleted($id) { global $sugar_config; if ($this->parent_type == 'Emails') { if (isset($sugar_config['email_default_delete_attachments']) && $sugar_config['email_default_delete_attachments'] == true) { $removeFile = getcwd() . "/{$sugar_config['upload_dir']}{$id}"; if (file_exists($removeFile)) { if (!unlink($removeFile)) { $GLOBALS['log']->error("*** Could not unlink() file: [ {$removeFile} ]"); } } } } // delete ecmprivatedocument parent::mark_deleted($id); } function deleteAttachment($isduplicate = "false") { if ($this->ACLAccess('edit')) { if ($isduplicate == "true") { return true; } $removeFile = clean_path(getAbsolutePath("{$GLOBALS['sugar_config']['upload_dir']}{$this->id}")); } if (file_exists($removeFile)) { if (!unlink($removeFile)) { $GLOBALS['log']->error("*** Could not unlink() file: [ {$removeFile} ]"); } else { $this->filename = ''; $this->file_mime_type = ''; $this->file = ''; $this->save(); return true; } } return false; } function get_summary_text() { return "$this->name"; } function create_list_query($order_by, $where, $show_deleted = 0) { $contact_required = ereg("contacts\.first_name", $where); $contact_required = 1; $query = "SELECT "; $custom_join = $this->custom_fields->getJOIN(); if ($contact_required) { $query .= "$this->table_name.*"; if (( $this->db->dbType == 'mysql' ) or ( $this->db->dbType == 'oci8' )) { $query .= ", concat(concat(contacts.first_name , ' '), contacts.last_name) AS contact_name"; } if ($this->db->dbType == 'mssql') { $query .= ", contacts.first_name + ' ' + contacts.last_name AS contact_name"; } $query .= ", contacts.assigned_user_id contact_name_owner"; if ($custom_join) { $query .= $custom_join['select']; } $query.= " FROM ecmprivatedocuments "; $query .= " LEFT JOIN contacts ON ecmprivatedocuments.contact_id=contacts.id "; if ($custom_join) { $query .= $custom_join['join']; } $where_auto = '1=1'; if ($show_deleted == 0) { $where_auto = " (contacts.deleted IS NULL OR contacts.deleted=0) AND ecmprivatedocuments.deleted=0"; } elseif ($show_deleted == 1) { $where_auto = " ecmprivatedocuments.deleted=0 "; } } else { $query .= ' id, name, parent_type, parent_id, contact_id, filename, date_modified '; if ($custom_join) { $query .= $custom_join['select']; } if ($custom_join) { $query .= $custom_join['join']; } $where_auto = '1=1'; if ($show_deleted == 0) { $where_auto = "deleted=0"; } elseif ($show_deleted == 1) { $where_auto = "deleted=1"; } } 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 ecmprivatedocuments.name"; } return $query; } function create_export_query(&$order_by, &$where) { $custom_join = $this->custom_fields->getJOIN(true, true); $query = "SELECT ecmprivatedocuments.*, contacts.first_name, contacts.last_name "; if ($custom_join) { $query .= $custom_join['select']; } $query .= " FROM ecmprivatedocuments "; $query .= " LEFT JOIN contacts ON ecmprivatedocuments.contact_id=contacts.id "; if ($custom_join) { $query .= $custom_join['join']; } $where_auto = " ecmprivatedocuments.deleted=0 AND (contacts.deleted IS NULL OR contacts.deleted=0)"; 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 ecmprivatedocuments.name"; return $query; } function fill_in_additional_list_fields() { $this->fill_in_additional_detail_fields(); } function fill_in_additional_detail_fields() { parent::fill_in_additional_detail_fields(); //TODO: Seems odd we need to clear out these values so that list views don't show the previous rows value if current value is blank $this->contact_name = ''; $this->contact_phone = ''; $this->contact_email = ''; $this->parent_name = ''; $this->contact_name_owner = ''; $this->contact_name_mod = ''; if (isset($this->contact_id) && $this->contact_id != '') { require_once("modules/Contacts/Contact.php"); $contact = new Contact(); $contact->retrieve($this->contact_id); $this->contact_name_mod = 'Contacts'; $this->contact_name = $contact->name; $this->contact_phone = $contact->phone_work; require_once("include/SugarEmailAddress/SugarEmailAddress.php"); $emailAddress = new SugarEmailAddress(); $this->contact_email = $emailAddress->getPrimaryAddress($contact); } $this->fill_in_additional_parent_fields(); } function fill_in_additional_parent_fields() { global $app_strings; global $beanFiles, $beanList; global $locale; $this->parent_name = ''; // cn: bug 6324 - load parent_type|name dynamically if (!empty($this->parent_type) and isset($beanFiles[$beanList[$this->parent_type]])) { require_once($beanFiles[$beanList[$this->parent_type]]); $parentBean = new $beanList[$this->parent_type](); // We need to set the $mod_strings to the parent_type value for the retrieve call on SugarBean global $mod_strings, $current_language; $mod_strings = return_module_language($current_language, $this->parent_type); $parentBean->retrieve($this->parent_id); $mod_strings = return_module_language($current_language, $this->module_dir); // cn: bug 10626 contacts, leads, users, etc. have no "name" column if (isset($parentBean->name) && !empty($parentBean->name)) { $this->parent_name = $parentBean->name; } elseif (method_exists($parentBean, '_create_proper_name_field')) { $parentBean->_create_proper_name_field(); $this->parent_name = $parentBean->full_name; } elseif (isset($parentBean->first_name) && isset($parentBean->last_name)) { $this->parent_name = $locale->getLocaleFormattedName($parentBean->first_name, $parentBean->last_name); } if (isset($parentBean->assigned_user_id) && !empty($parentBean->assigned_user_id)) { $this->parent_name_owner = $parentBean->assigned_user_id; $this->parent_name_mod = $this->parent_type; } } } function _create_proper_name_field() { global $locale; if (isset($this->contact_id) && $this->contact_id != '') { require_once("modules/Contacts/Contact.php"); $contact = new Contact(); $contact->retrieve($this->contact_id); if (isset($contact->first_name, $contact->last_name)) { global $locale; $full_name = $locale->getLocaleFormattedName($contact->first_name, $contact->last_name, $contact->salutation, $contact->title); $this->contact_name = $full_name; } } } function get_list_view_data() { $ecmprivatedocument_fields = $this->get_list_view_array(); global $app_list_strings, $focus, $action, $currentModule, $mod_strings, $sugar_config; $this->_create_proper_name_field(); if (isset($this->parent_type)) { $ecmprivatedocument_fields['PARENT_MODULE'] = $this->parent_type; } if (!isset($this->filename) || $this->filename != '') { $file_path = UploadFile::get_file_path($this->filename, $this->id); if (file_exists($file_path)) { $save_file = urlencode(basename(UploadFile::get_url($this->filename, $this->id))); $ecmprivatedocument_fields['FILENAME'] = $this->filename; $ecmprivatedocument_fields['FILE_URL'] = "index.php?entryPoint=download&id=" . $save_file . "&type=EcmPrivateDocuments"; } } if (isset($this->contact_name)) { $ecmprivatedocument_fields['CONTACT_NAME'] = $this->contact_name; } global $current_language; $mod_strings = return_module_language($current_language, 'EcmPrivateDocuments'); $ecmprivatedocument_fields['STATUS'] = $mod_strings['LBL_ECMPRIVATEDOCUMENT_STATUS']; $user = new User(); $user->retrieve($this->created_by); $ecmprivatedocument_fields['CREATED_BY_NAME'] = $user->full_name; return $ecmprivatedocument_fields; } 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; } function bean_implements($interface) { switch ($interface) { case 'ACL':return true; } return false; } } ?>