'contracts', ); function EcmFkBook() { parent :: SugarBean(); $this->setupCustomFields('EcmFkBooks'); //parameter is module name //$this->disable_row_level_security = false; } function save($check_notify = false) { if (empty($this->id) || $this->new_with_id) { if (false) { //!empty($this->uploadfile)) $this->filename = $this->uploadfile; if (empty($this->id)) { $this->id = create_guid(); $this->new_with_id = true; } $Revision = new EcmFkBookRevision(); //save revision. $Revision->change_log = translate('DEF_CREATE_LOG', 'EcmFkBooks'); $Revision->revision = $this->revision; $Revision->ecmfkbook_id = $this->id; $Revision->filename = $this->filename; $Revision->file_ext = $this->file_ext; $Revision->file_mime_type = $this->file_mime_type; $Revision->save(); //Move file saved during populatefrompost to match the revision id rather than ecmfkbook id rename(UploadFile :: get_url($this->filename, $this->id), UploadFile :: get_url($this->filename, $Revision->id)); //update ecmfkbook with latest revision id $this->process_save_dates = false; //make sure that conversion does not happen again. $this->ecmfkbook_revision_id = $Revision->id; } //set relationship field values if contract_id is passed (via subpanel create) if (!empty($_POST['contract_id'])) { $save_revision['ecmfkbook_revision_id'] = $this->document_revision_id; $this->load_relationship('contracts'); $this->contracts->add($_POST['contract_id'], $save_revision); } if ((isset($_POST['load_signed_id']) and !empty($_POST['load_signed_id']))) { $query = "update linked_ecmfkbooks set deleted=1 where id='" . $_POST['load_signed_id'] . "'"; $this->db->query($query); } } return parent :: save($check_notify); } function get_summary_text() { return "$this->ecmfkbook_name"; } function is_authenticated() { return $this->authenticated; } function fill_in_additional_list_fields() { $this->fill_in_additional_detail_fields(); } function fill_in_additional_detail_fields() { goto jump; global $theme; global $current_language; global $timedate; global $locale; parent::fill_in_additional_detail_fields(); $mod_strings = return_module_language($current_language, 'EcmFkBooks'); $query = "SELECT filename,revision,file_ext FROM ecmfkbook_revisions WHERE id='$this->document_revision_id'"; $result = $this->db->query($query); $row = $this->db->fetchByAssoc($result); //popuplate filename if (isset($row['filename'])) $this->filename = $row['filename']; //$this->latest_revision = $row['revision']; if (isset($row['revision'])) $this->revision = $row['revision']; //populate the file url. //image is selected based on the extension name _icon_inline, extension is stored in ecmfkbook_revisions. //if file is not found then default image file will be used. global $img_name; global $img_name_bare; if (!empty($row['file_ext'])) { $img_name = SugarThemeRegistry::current()->getImageURL(strtolower($row['file_ext']) . "_image_inline.gif"); $img_name_bare = strtolower($row['file_ext']) . "_image_inline"; } //set default file name. if (!empty($img_name) && file_exists($img_name)) { $img_name = $img_name_bare; } else { $img_name = "def_image_inline"; //todo change the default image. } if ($this->ACLAccess('DetailView')) { $this->file_url = "" . SugarThemeRegistry::current()->getImage($img_name, 'alt="' . $mod_strings['LBL_LIST_VIEW_DOCUMENT'] . '" border="0"') . ""; $this->file_url_noimage = basename(UploadFile :: get_url($this->filename, $this->ecmfkbook_revision_id)); } else { $this->file_url = ""; $this->file_url_noimage = ""; } //get last_rev_by user name. $query = "SELECT first_name,last_name, ecmfkbook_revisions.date_entered as rev_date FROM users, document_revisions WHERE users.id = document_revisions.created_by and document_revisions.id = '$this->document_revision_id'"; $result = $this->db->query($query, true, "Eror fetching user name: "); $row = $this->db->fetchByAssoc($result); if (!empty($row)) { $this->last_rev_created_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']); $this->last_rev_create_date = $timedate->to_display_date_time($row['rev_date']); } global $app_list_strings; if (!empty($this->status_id)) { //_pp($this->status_id); $this->status = $app_list_strings['ecmfkbook_status_dom'][$this->status_id]; } $this->related_doc_name = EcmFkBook::get_ecmfkbook_name($this->related_doc_id); $this->related_doc_rev_number = EcmFkBookRevision::get_ecmfkbook_revision_name($this->related_doc_rev_id); $this->save_file = basename($this->file_url_noimage); jump: } function list_view_parse_additional_sections(& $list_form, $xTemplateSection) { return $list_form; } 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; $query = "SELECT ecmfkbooks.*"; if ($custom_join) { $query .= $custom_join['select']; } $query .= " FROM ecmfkbooks "; if ($custom_join) { $query .= $custom_join['join']; } $where_auto = " ecmfkbooks.deleted = 0"; if ($where != "") $query .= " WHERE $where AND " . $where_auto; else $query .= " WHERE " . $where_auto; if ($order_by != "") $query .= " ORDER BY $order_by"; else $query .= " ORDER BY ecmfkbooks.document_name"; return $query; } function get_list_view_data() { global $current_language; $app_list_strings = return_app_list_strings_language($current_language); $ecmfkbook_fields = $this->get_list_view_array(); $ecmfkbook_fields['BOOK_AMOUNT_COLORED'] = (floatval($amount = $ecmfkbook_fields['BOOK_AMOUNT']) < 0) ? ('' . $amount . '') : $amount; //$documentDate = new DateTime(str_replace('.', '-', $ecmfkbook_fields['DATE_DOCUMENT'])); $documentDate = DateTime::createFromFormat('d.m.Y', $ecmfkbook_fields['DATE_DOCUMENT']); $ecmfkbook_fields['BOOK_MONTH'] = $documentDate->format('m/Y'); //$ecmfkbook_fields['FILE_URL'] = $this->file_url; //$ecmfkbook_fields['FILE_URL_NOIMAGE'] = $this->file_url_noimage; //$ecmfkbook_fields['LAST_REV_CREATED_BY'] = $this->last_rev_created_name; //$ecmfkbook_fields['CATEGORY_ID'] = empty ($this->category_id) ? "" : $app_list_strings['document_category_dom'][$this->category_id]; //$ecmfkbook_fields['SUBCATEGORY_ID'] = empty ($this->subcategory_id) ? "" : $app_list_strings['document_subcategory_dom'][$this->subcategory_id]; //$ecmfkbook_fields['DOCUMENT_NAME_JAVASCRIPT'] = $GLOBALS['db']->helper->escape_quote($document_fields['DOCUMENT_NAME']); // echo '
' . var_export($this->field_defs, true) . '
'; // echo '
' . var_export($ecmfkbook_fields, true) . '
'; // exit; //echo '
' . var_export((floatval($amount = $ecmfkbook_fields['BOOK_AMOUNT']) < 0), true) . '
'; //exit; return $ecmfkbook_fields; } function mark_relationships_deleted($id) { //do nothing, this call is here to avoid default delete processing since //delete.php handles deletion of ecmfkbook revisions. } function bean_implements($interface) { switch ($interface) { case 'ACL' : return true; } return false; } //static function. function get_ecmfkbook_name($doc_id) { if (empty($doc_id)) return null; $db = DBManagerFactory::getInstance(); $query = "select ecmfkbook_name from documents where id='$doc_id'"; $result = $db->query($query); if (!empty($result)) { $row = $db->fetchByAssoc($result); if (!empty($row)) { return $row['ecmfkbook_name']; } } return null; } }