function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     $focus = new iFrame();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (empty($_REQUEST['status']) || $_REQUEST['status'] == 'off') {
         $focus->status = 0;
     } else {
         $focus->status = 1;
     }
     $focus->save();
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         $this->handleRedirect('');
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/EmailTemplates/EmailTemplate.php';
     require_once 'modules/Documents/Document.php';
     require_once 'modules/DocumentRevisions/DocumentRevision.php';
     require_once 'modules/Notes/Note.php';
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize, $upload_dir;
     global $mod_strings;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $return_id = $focus->save();
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = 10;
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     for ($i = 0; $i < $max_files_upload; $i++) {
         $note = new Note();
         $upload_file = new UploadFile('email_attachment' . $i);
         if ($upload_file == -1) {
             continue;
         }
         if (isset($_FILES['email_attachment' . $i]) && $upload_file->confirm_upload()) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id)) {
             if (empty($_REQUEST['old_id'])) {
                 // to support duplication of email templates
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNoteId = $newNote->save();
                 $dupeFile = new UploadFile('duplicate');
                 $dupeFile->duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         array_push($focus->saved_attachments, $note);
         $note->id = $note_id;
         $note->file->final_move($note->id);
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     for ($i = 0; $i < 10; $i++) {
         if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) {
             $doc = new Document();
             $docRev = new DocumentRevision();
             $docNote = new Note();
             $noteFile = new UploadFile('none');
             $doc->retrieve($_REQUEST['documentId' . $i]);
             $docRev->retrieve($doc->document_revision_id);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->id;
             $docNote->parent_type = 'Emails';
             $docNote->file_mime_type = $docRev->file_mime_type;
             $docId = $docNote = $docNote->save();
             $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename);
         }
     }
     ////	END ATTACHMENTS FROM DOCUMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	REMOVE ATTACHMENTS
     if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) {
         foreach ($_REQUEST['remove_attachment'] as $noteId) {
             $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $current_user;
     require_once 'include/formbase.php';
     $focus = new Opportunity();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (empty($_POST['currency_id'])) {
         $currency_id = $current_user->getPreference('currency');
         if (isset($currency_id)) {
             $focus->currency_id = $currency_id;
         }
     }
     $focus = populateFromPost($prefix, $focus);
     if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) {
         ACLController::displayNoAccess(true);
     }
     $check_notify = FALSE;
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     }
     $focus->save($check_notify);
     if (!empty($_POST['duplicate_parent_id'])) {
         clone_relationship($focus->db, array('opportunities_contacts'), 'opportunity_id', $_POST['duplicate_parent_id'], $focus->id);
     }
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, "Opportunities");
     } else {
         return $focus;
     }
 }
Exemple #4
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $do_save = true, $exist_lead = null)
 {
     require_once 'modules/Campaigns/utils.php';
     require_once 'include/formbase.php';
     if (empty($exist_lead)) {
         $focus = new Lead();
     } else {
         $focus = $exist_lead;
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     //Check for duplicate Leads
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateLeads = $this->checkForDuplicates($prefix);
         if (isset($duplicateLeads)) {
             //Set the redirect location to call the ShowDuplicates action.  This will map to view.showduplicates.php
             $location = 'module=Leads&action=ShowDuplicates';
             $get = '';
             if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
                 $get .= '&inbound_email_id=' . $_POST['inbound_email_id'];
             }
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&Leadsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&Leadsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Leads{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Leads{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Leads{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate lead ids in redirect get string
             $i = 0;
             foreach ($duplicateLeads as $lead) {
                 $get .= "&duplicate[{$i}]=" . $lead['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= "&return_module=";
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= "Leads";
             }
             $get .= "&return_action=";
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             if (!empty($_POST['return_id'])) {
                 $get .= "&return_id=" . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             // for InboundEmail flow
             if (!empty($_POST['start'])) {
                 $get .= '&start=' . $_POST['start'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     if (!isset($_POST[$prefix . 'email_opt_out'])) {
         $focus->email_opt_out = 0;
     }
     if (!isset($_POST[$prefix . 'do_not_call'])) {
         $focus->do_not_call = 0;
     }
     if ($do_save) {
         if (!empty($GLOBALS['check_notify'])) {
             $focus->save($GLOBALS['check_notify']);
         } else {
             $focus->save(FALSE);
         }
     }
     $return_id = $focus->id;
     if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) {
         $prospect = new Prospect();
         $prospect->retrieve($_POST[$prefix . 'prospect_id']);
         $prospect->lead_id = $focus->id;
         // Set to keep email in target
         $prospect->in_workflow = true;
         $prospect->save();
         //if prospect id exists, make sure we are coming from prospect detail
         if (strtolower($_POST['return_module']) == 'prospects' && strtolower($_POST['return_action']) == 'detailview') {
             //create campaing_log entry
             if (isset($focus->campaign_id) && $focus->campaign_id != null) {
                 campaign_log_lead_entry($focus->campaign_id, $prospect, $focus, 'lead');
             }
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         if (!isset($current_user)) {
             global $current_user;
         }
         // fake this case like it's already saved.
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Leads';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('leads');
         $email->leads->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, 'Leads');
     } else {
         return $focus;
     }
 }
Exemple #5
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $id = null, $searchModuleBean)
 {
     global $current_user, $timedate;
     $focus = new SavedSearch();
     if ($id) {
         $focus->retrieve($id);
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced', 'Calls_divs', 'ACLRoles_divs');
     $contents = $_REQUEST;
     if ($id == null) {
         $focus->name = $contents['saved_search_name'];
     }
     $focus->search_module = $contents['search_module'];
     foreach ($contents as $input => $value) {
         if (in_array($input, $ignored_inputs)) {
             unset($contents[$input]);
             continue;
         }
         //Filter date fields to ensure it is saved to DB format, but also avoid empty values
         if (!empty($value) && preg_match('/^(start_range_|end_range_|range_)?(.*?)(_advanced|_basic)$/', $input, $match)) {
             $field = $match[2];
             if (isset($searchModuleBean->field_defs[$field]['type'])) {
                 $type = $searchModuleBean->field_defs[$field]['type'];
                 //Avoid macro values for the date types
                 if (($type == 'date' || $type == 'datetime' || $type == 'datetimecombo') && !preg_match('/^\\[.*?\\]$/', $value)) {
                     $db_format = $timedate->to_db_date($value, false);
                     $contents[$input] = $db_format;
                 } else {
                     if ($type == 'int' || $type == 'currency' || $type == 'decimal' || $type == 'float') {
                         if (preg_match('/[^\\d]/', $value)) {
                             require_once 'modules/Currencies/Currency.php';
                             $contents[$input] = unformat_number($value);
                             //Flag this value as having been unformatted
                             $contents[$input . '_unformatted_number'] = true;
                             //If the type is of currency and there was a currency symbol (non-digit), save the symbol
                             if ($type == 'currency' && preg_match('/^([^\\d])/', $value, $match)) {
                                 $contents[$input . '_currency_symbol'] = $match[1];
                             }
                         } else {
                             //unset any flags
                             if (isset($contents[$input . '_unformatted_number'])) {
                                 unset($contents[$input . '_unformatted_number']);
                             }
                             if (isset($contents[$input . '_currency_symbol'])) {
                                 unset($contents[$input . '_currency_symbol']);
                             }
                         }
                     }
                 }
             }
         }
     }
     $contents['advanced'] = true;
     $focus->contents = base64_encode(serialize($contents));
     $focus->assigned_user_id = $current_user->id;
     $focus->new_schema = true;
     $saved_search_id = $focus->save();
     $GLOBALS['log']->debug("Saved record with id of " . $focus->id);
     $orderBy = empty($contents['orderBy']) ? 'name' : $contents['orderBy'];
     $search_query = "&orderBy=" . $orderBy . "&sortOrder=" . $contents['sortOrder'] . "&query=" . $_REQUEST['query'] . "&searchFormTab=" . $_REQUEST['searchFormTab'] . '&showSSDIV=' . $contents['showSSDIV'];
     if ($redirect) {
         $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true');
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $current_user;
     require_once 'modules/Calls/Call.php';
     require_once 'include/formbase.php';
     global $timedate;
     if (isset($_POST['should_remind']) && $_POST['should_remind'] == '0') {
         $_POST['reminder_time'] = -1;
     }
     if (!isset($_POST['reminder_time'])) {
         $_POST['reminder_time'] = $current_user->getPreference('reminder_time');
         if (empty($_POST['reminder_time'])) {
             $_POST['reminder_time'] = -1;
         }
     }
     if (!empty($_POST[$prefix . 'time_hour_start']) && empty($_POST['time_start'])) {
         $_POST['time_start'] = $_POST[$prefix . 'time_hour_start'] . ":" . $_POST[$prefix . 'time_minute_start'];
     }
     if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) {
         $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(true), $_POST[$prefix . 'meridiem']);
     }
     $focus = new Call();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     ///////////////////////////////////////////////////////////////////////////
     ////	REMOVE INVITEE RELATIONSHIPS
     if (!empty($_POST['user_invitees'])) {
         $focus->load_relationship('users');
         // this query to preserve accept_status across deletes
         $q = 'SELECT mu.user_id, mu.accept_status FROM calls_users mu WHERE mu.call_id = \'' . $focus->id . '\' AND mu.deleted = 0';
         $r = $focus->db->query($q);
         $acceptStatusUsers = array();
         while ($a = $focus->db->fetchByAssoc($r)) {
             $acceptStatusUsers[$a['user_id']] = $a['accept_status'];
         }
         $focus->users->delete($focus->id);
     }
     if (!empty($_POST['contact_invitees'])) {
         $focus->load_relationship('contacts');
         // this query to preserve accept_status across deletes
         $q = 'SELECT mc.contact_id, mc.accept_status FROM calls_contacts mc WHERE mc.call_id = \'' . $focus->id . '\' AND mc.deleted = 0';
         $r = $focus->db->query($q);
         $acceptStatusContacts = array();
         while ($a = $focus->db->fetchByAssoc($r)) {
             $acceptStatusContacts[$a['contact_id']] = $a['accept_status'];
         }
         $focus->contacts->delete($focus->id);
     }
     ////	END REMOVE
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	REBUILD INVITEE RELATIONSHIPS
     if (!empty($_POST['user_invitees'])) {
         $existing_users = array();
         $_POST['user_invitees'] = preg_replace('/\\,$/', '', $_POST['user_invitees']);
         if (!empty($_POST['existing_invitees'])) {
             $existing_users = explode(",", $_POST['existing_invitees']);
         }
         $focus->users_arr = explode(",", $_POST['user_invitees']);
     }
     if (!empty($_POST['contact_invitees'])) {
         $_POST['contact_invitees'] = preg_replace('/\\,$/', '', $_POST['contact_invitees']);
         $existing_contacts = array();
         if (!empty($_POST['existing_contact_invitees'])) {
             $existing_contacts = explode(",", $_POST['existing_contact_invitees']);
         }
         $focus->contacts_arr = explode(",", $_POST['contact_invitees']);
     }
     if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
         $focus->contacts_arr[] = $_POST['parent_id'];
     }
     $focus->save(true);
     $return_id = $focus->id;
     if (!empty($focus->users_arr) && is_array($focus->users_arr)) {
         foreach ($focus->users_arr as $user_id) {
             if (empty($user_id) || isset($existing_users[$user_id])) {
                 continue;
             }
             if (!isset($focus->users)) {
                 $focus->load_relationship('users');
             }
             $focus->users->add($user_id);
             // update query to preserve accept_status
             if (isset($acceptStatusUsers[$user_id]) && !empty($acceptStatusUsers[$user_id])) {
                 $qU = 'UPDATE calls_users mu SET mu.accept_status = \'' . $acceptStatusUsers[$user_id] . '\' ';
                 $qU .= 'WHERE mu.deleted = 0 ';
                 $qU .= 'AND mu.call_id = \'' . $focus->id . '\' ';
                 $qU .= 'AND mu.user_id = \'' . $user_id . '\'';
                 $focus->db->query($qU);
             }
         }
     }
     if (!empty($focus->contacts_arr) && is_array($focus->contacts_arr)) {
         foreach ($focus->contacts_arr as $contact_id) {
             if (empty($contact_id) || isset($existing_contacts[$contact_id])) {
                 continue;
             }
             if (!is_array($focus->contacts)) {
                 $focus->load_relationship('contacts');
             }
             $focus->contacts->add($contact_id);
             // update query to preserve accept_status
             if (isset($acceptStatusContacts[$contact_id]) && !empty($acceptStatusContacts[$contact_id])) {
                 $qU = 'UPDATE calls_contacts mc SET mc.accept_status = \'' . $acceptStatusContacts[$contact_id] . '\' ';
                 $qU .= 'WHERE mc.deleted = 0 ';
                 $qU .= 'AND mc.call_id = \'' . $focus->id . '\' ';
                 $qU .= 'AND mc.contact_id = \'' . $contact_id . '\'';
                 $focus->db->query($qU);
             }
         }
     }
     // set organizer to auto-accept
     $focus->set_accept_status($current_user, 'accept');
     ////	END REBUILD INVITEE RELATIONSHIPS
     ///////////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, 'Calls');
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $theme, $current_user;
     require_once 'include/formbase.php';
     global $timedate;
     $focus = new Contact();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!empty($_POST[$prefix . 'new_reports_to_id'])) {
         $focus->retrieve($_POST[$prefix . 'new_reports_to_id']);
         $focus->reports_to_id = $_POST[$prefix . 'record'];
     } else {
         $focus = populateFromPost($prefix, $focus);
         if (!empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix . 'old_portal_password']) {
             $focus->portal_password = md5($focus->portal_password);
         }
         if (!isset($_POST[$prefix . 'email_opt_out'])) {
             $focus->email_opt_out = 0;
         }
         if (!isset($_POST[$prefix . 'do_not_call'])) {
             $focus->do_not_call = 0;
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if ($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect') {
         if (!empty($_POST[$prefix . 'sync_contact'])) {
             $focus->contacts_users_id = $current_user->id;
         } else {
             if (!isset($focus->users)) {
                 $focus->load_relationship('user_sync');
             }
             $focus->contacts_users_id = null;
             $focus->user_sync->delete($focus->id, $current_user->id);
         }
     }
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['dup_checked'])) {
         $duplicateContacts = $this->checkForDuplicates($prefix);
         if (isset($duplicateContacts)) {
             $location = 'module=Contacts&action=ShowDuplicates';
             $get = '';
             if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
                 $get .= '&inbound_email_id=' . $_POST['inbound_email_id'];
             }
             // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&Contactsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&Contactsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Contacts{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Contacts{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Contacts{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate contact id's in redirect get string
             $i = 0;
             foreach ($duplicateContacts as $contact) {
                 $get .= "&duplicate[{$i}]=" . $contact['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= "&return_module=";
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= "Contacts";
             }
             $get .= "&return_action=";
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             //else $get .= "DetailView";
             if (!empty($_POST['return_id'])) {
                 $get .= "&return_id=" . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             // for InboundEmail flow
             if (!empty($_POST['start'])) {
                 $get .= '&start=' . $_POST['start'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             //now redirect the post to modules/Contacts/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     global $current_user;
     if (is_admin($current_user)) {
         if (!isset($_POST[$prefix . 'portal_active'])) {
             $focus->portal_active = '0';
         }
         //if no password is set set account to inactive for portal
         if (empty($_POST[$prefix . 'portal_name'])) {
             $focus->portal_active = '0';
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         // fake this case like it's already saved.
         $focus->save($check_notify);
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Contacts';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('contacts');
         $email->contacts->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         $trackerManager = TrackerManager::getInstance();
         $timeStamp = TimeDate::getInstance()->nowDb();
         if ($monitor = $trackerManager->getMonitor('tracker')) {
             $monitor->setValue('action', 'detailview');
             $monitor->setValue('user_id', $GLOBALS['current_user']->id);
             $monitor->setValue('module_name', 'Contacts');
             $monitor->setValue('date_modified', $timeStamp);
             $monitor->setValue('visible', 1);
             if (!empty($this->bean->id)) {
                 $monitor->setValue('item_id', $return_id);
                 $monitor->setValue('item_summary', $focus->get_summary_text());
             }
             $trackerManager->saveMonitor($monitor, true, true);
         }
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Contacts';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&first_name=' . urlencode($focus->first_name);
         $get .= '&last_name=' . urlencode($focus->last_name);
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $theme, $current_user;
     require_once 'include/formbase.php';
     $galleria = $_POST['galleria_c'];
     $focus = new Realty();
     if (!empty($_POST[$prefix . 'new_reports_to_id'])) {
         $focus->retrieve($_POST[$prefix . 'new_reports_to_id']);
         $focus->reports_to_id = $_POST[$prefix . 'record'];
     } else {
         $focus = populateFromPost($prefix, $focus);
     }
     if (isset($galleria)) {
         $focus->galleria_c = $galleria;
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['dup_checked'])) {
         $duplicateRealty = $this->checkForDuplicates($prefix);
         if (isset($duplicateRealty)) {
             $focus->possible_duplicate = 1;
             $_SESSION['duplicateRealty'] = $duplicateRealty;
             $location = 'module=Realty&action=ShowDuplicates&record=' . $_POST['record'];
             $get = '';
             if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
                 $get .= '&inbound_email_id=' . $_POST['inbound_email_id'];
             }
             // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&Realtyrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&Realtyrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Realty{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Realty{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Realty{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate realty id's in redirect get string
             $i = 0;
             foreach ($duplicateRealty as $realty) {
                 $get .= "&duplicate[{$i}]=" . $realty['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= "&return_module=";
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= "Realty";
             }
             $get .= "&return_action=";
             if (!empty($_POST['return_action'])) {
                 $get .= 'EditView';
             }
             //else $get .= "DetailView";
             if (!empty($_POST['return_id'])) {
                 $get .= "&return_id=" . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             // for InboundEmail flow
             if (!empty($_POST['start'])) {
                 $get .= '&start=' . $_POST['start'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             //now redirect the post to modules/Realty/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     //    $focus->load_relationship('realty_realty_1');
     //    $focus->realty_realty_1->delete($focus->id);
     //    foreach ($_SESSION['duplicateRealty'] as $realty)
     //    {
     //        $focus->realty_realty_1->add($realty['id']);
     //    }
     $_SESSION['duplicateRealty'] = array();
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Realty';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&name=' . urlencode($focus->name);
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
 /**
  * handles save functionality for meetings
  * @param	string prefix
  * @param	bool redirect default True
  * @param	bool useRequired default True
  */
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     global $current_user;
     global $timedate;
     $focus = new Meeting();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!isset($_POST['reminder_checked']) or isset($_POST['reminder_checked']) && $_POST['reminder_checked'] == '0') {
         $_POST['reminder_time'] = null;
     }
     if (!isset($_POST['reminder_time'])) {
         $_POST['reminder_time'] = $current_user->getPreference('reminder_time');
         $_POST['reminder_checked'] = 1;
     }
     $time_format = $timedate->get_user_time_format();
     $time_separator = ":";
     if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
         $time_separator = $match[1];
     }
     if (!empty($_POST[$prefix . 'time_hour_start']) && empty($_POST['time_start'])) {
         $_POST[$prefix . 'time_start'] = $_POST[$prefix . 'time_hour_start'] . $time_separator . $_POST[$prefix . 'time_minute_start'];
     }
     if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) {
         $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(true), $_POST[$prefix . 'meridiem']);
     }
     if (isset($_POST[$prefix . 'time_start']) && strlen($_POST[$prefix . 'date_start']) == 10) {
         $_POST[$prefix . 'date_start'] = $_POST[$prefix . 'date_start'] . ' ' . $_POST[$prefix . 'time_start'];
     }
     // retrieve happens here
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (isset($_POST['isSaveFromDetailView']) && $_POST['isSaveFromDetailView'] == 'true') {
         $focus->save(true);
         $return_id = $focus->id;
     } else {
         ///////////////////////////////////////////////////////////////////////////
         ////	REMOVE INVITEE RELATIONSHIPS
         if (!empty($_POST['user_invitees'])) {
             $userInvitees = explode(',', trim($_POST['user_invitees'], ','));
         } else {
             $userInvitees = array();
         }
         // Calculate which users to flag as deleted and which to add
         $deleteUsers = array();
         $focus->load_relationship('users');
         // Get all users for the meeting
         $q = 'SELECT mu.user_id, mu.accept_status FROM meetings_users mu WHERE mu.meeting_id = \'' . $focus->id . '\'';
         $r = $focus->db->query($q);
         $acceptStatusUsers = array();
         while ($a = $focus->db->fetchByAssoc($r)) {
             if (!in_array($a['user_id'], $userInvitees)) {
                 $deleteUsers[$a['user_id']] = $a['user_id'];
             } else {
                 $acceptStatusUsers[$a['user_id']] = $a['accept_status'];
             }
         }
         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 meetings_users set deleted = 1 where user_id in ({$sql}) AND meeting_id = '" . $focus->id . "'";
             $focus->db->query($sql);
         }
         // Get all contacts for the meeting
         if (!empty($_POST['contact_invitees'])) {
             $contactInvitees = explode(',', trim($_POST['contact_invitees'], ','));
         } else {
             $contactInvitees = array();
         }
         $deleteContacts = array();
         $focus->load_relationship('contacts');
         $q = 'SELECT mu.contact_id, mu.accept_status FROM meetings_contacts mu WHERE mu.meeting_id = \'' . $focus->id . '\'';
         $r = $focus->db->query($q);
         $acceptStatusContacts = array();
         while ($a = $focus->db->fetchByAssoc($r)) {
             if (!in_array($a['contact_id'], $contactInvitees)) {
                 $deleteContacts[$a['contact_id']] = $a['contact_id'];
             } else {
                 $acceptStatusContacts[$a['contact_id']] = $a['accept_status'];
             }
         }
         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 meetings_contacts set deleted = 1 where contact_id in ({$sql}) AND meeting_id = '" . $focus->id . "'";
             $focus->db->query($sql);
         }
         if (!empty($_POST['lead_invitees'])) {
             $leadInvitees = explode(',', trim($_POST['lead_invitees'], ','));
         } else {
             $leadInvitees = array();
         }
         $deleteLeads = array();
         $focus->load_relationship('leads');
         $q = 'SELECT mu.lead_id, mu.accept_status FROM meetings_leads mu WHERE mu.meeting_id = \'' . $focus->id . '\'';
         $r = $focus->db->query($q);
         $acceptStatusLeads = array();
         while ($a = $focus->db->fetchByAssoc($r)) {
             if (!in_array($a['lead_id'], $leadInvitees)) {
                 $deleteLeads[$a['lead_id']] = $a['lead_id'];
             } else {
                 $acceptStatusLeads[$a['lead_id']] = $a['accept_status'];
             }
         }
         if (count($deleteLeads) > 0) {
             $sql = '';
             foreach ($deleteLeads 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 meetings_leads set deleted = 1 where lead_id in ({$sql}) AND meeting_id = '" . $focus->id . "'";
             $focus->db->query($sql);
         }
         ////	END REMOVE
         ///////////////////////////////////////////////////////////////////////////
         ///////////////////////////////////////////////////////////////////////////
         ////	REBUILD INVITEE RELATIONSHIPS
         $focus->users_arr = array();
         $focus->users_arr = $userInvitees;
         $focus->contacts_arr = array();
         $focus->contacts_arr = $contactInvitees;
         $focus->leads_arr = array();
         $focus->leads_arr = $leadInvitees;
         if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
             $focus->contacts_arr[] = $_POST['parent_id'];
         }
         if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') {
             $focus->leads_arr[] = $_POST['parent_id'];
         }
         // Call the Meeting module's save function to handle saving other fields besides
         // the users and contacts relationships
         $focus->save(true);
         $return_id = $focus->id;
         // Process users
         $existing_users = array();
         if (!empty($_POST['existing_invitees'])) {
             $existing_users = explode(",", trim($_POST['existing_invitees'], ','));
         }
         foreach ($focus->users_arr as $user_id) {
             if (empty($user_id) || isset($existing_users[$user_id]) || isset($deleteUsers[$user_id])) {
                 continue;
             }
             if (!isset($acceptStatusUsers[$user_id])) {
                 $focus->users->add($user_id);
             } else {
                 // update query to preserve accept_status
                 $qU = 'UPDATE meetings_users SET deleted = 0, accept_status = \'' . $acceptStatusUsers[$user_id] . '\' ';
                 $qU .= 'WHERE meeting_id = \'' . $focus->id . '\' ';
                 $qU .= 'AND user_id = \'' . $user_id . '\'';
                 $focus->db->query($qU);
             }
         }
         // Process contacts
         $existing_contacts = array();
         if (!empty($_POST['existing_contact_invitees'])) {
             $existing_contacts = explode(",", trim($_POST['existing_contact_invitees'], ','));
         }
         foreach ($focus->contacts_arr as $contact_id) {
             if (empty($contact_id) || isset($exiting_contacts[$contact_id]) || isset($deleteContacts[$contact_id])) {
                 continue;
             }
             if (!isset($acceptStatusContacts[$contact_id])) {
                 $focus->contacts->add($contact_id);
             } else {
                 // update query to preserve accept_status
                 $qU = 'UPDATE meetings_contacts SET deleted = 0, accept_status = \'' . $acceptStatusContacts[$contact_id] . '\' ';
                 $qU .= 'WHERE meeting_id = \'' . $focus->id . '\' ';
                 $qU .= 'AND contact_id = \'' . $contact_id . '\'';
                 $focus->db->query($qU);
             }
         }
         // Process leads
         $existing_leads = array();
         if (!empty($_POST['existing_lead_invitees'])) {
             $existing_leads = explode(",", trim($_POST['existing_lead_invitees'], ','));
         }
         foreach ($focus->leads_arr as $lead_id) {
             if (empty($lead_id) || isset($exiting_leads[$lead_id]) || isset($deleteLeads[$lead_id])) {
                 continue;
             }
             if (!isset($acceptStatusLeads[$lead_id])) {
                 $focus->leads->add($lead_id);
             } else {
                 // update query to preserve accept_status
                 $qU = 'UPDATE meetings_leads SET deleted = 0, accept_status = \'' . $acceptStatusLeads[$lead_id] . '\' ';
                 $qU .= 'WHERE meeting_id = \'' . $focus->id . '\' ';
                 $qU .= 'AND lead_id = \'' . $lead_id . '\'';
                 $focus->db->query($qU);
             }
         }
         // set organizer to auto-accept
         $focus->set_accept_status($current_user, 'accept');
         ////	END REBUILD INVITEE RELATIONSHIPS
         ///////////////////////////////////////////////////////////////////////////
     }
     if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Home') {
         header("Location: index.php?module=Home&action=index");
     } else {
         if ($redirect) {
             handleRedirect($return_id, 'Meetings');
         } else {
             return $focus;
         }
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/Suppliers/Supplier.php';
     require_once 'include/utils.php';
     require_once 'include/formbase.php';
     $focus = new Supplier();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateSuppliers = $this->checkForDuplicates($prefix);
         if (isset($duplicateSuppliers)) {
             $get = 'module=Suppliers&action=ShowDuplicates';
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Suppliers{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Suppliers{$field}=" . urlencode($focus->{$field});
                 }
             }
             //create list of suspected duplicate supplier id's in redirect get string
             $i = 0;
             foreach ($duplicateSuppliers as $supplier) {
                 $get .= "&duplicate[{$i}]=" . $supplier['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= '&return_module=';
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= 'Suppliers';
             }
             $get .= '&return_action=';
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             } else {
                 $get .= 'DetailView';
             }
             if (!empty($_POST['return_id'])) {
                 $get .= '&return_id=' . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             //echo $get;
             //die;
             //now redirect the post to modules/Suppliers/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $get));
             } else {
                 if (!empty($_POST['to_pdf'])) {
                     $get .= '&to_pdf=' . $_POST['to_pdf'];
                 }
                 header("Location: index.php?{$get}");
             }
             return null;
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Suppliers';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&name=' . $focus->name;
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         handleRedirect($return_id, 'Suppliers');
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/Feeds/Feed.php';
     require_once 'include/formbase.php';
     global $timedate;
     $focus = new Feed();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     //if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 'off';
     //if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 'off';
     /*
      if (!defined('DOMIT_RSS_INCLUDE_PATH')) {
                     define('DOMIT_RSS_INCLUDE_PATH', "include/domit_rss/");
             }
             require_once(DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss.php');
     
     
     print $focus->url;
             $rssdoc = new xml_domit_rss_document($focus->url,'cache/feeds/',3600);
     	if (  $rssdoc == null)
     { 
     return;
     }
     	$currChannel = $rssdoc->getChannel(0);
     
             $focus->title = $currChannel->getTitle();
     */
     $focus->save();
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/Quotes/Quote.php';
     require_once 'modules/QuoteLines/QuoteLine.php';
     require_once 'log4php/LoggerManager.php';
     require_once 'include/formbase.php';
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $focus = new Quote();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) {
         ACLController::displayNoAccess(true);
     }
     ///// Retrive old status ///////
     $old_bean = new Products();
     $old_bean->retrieve($focus->product_id);
     $old_status = $old_bean->status;
     //////////////////////////////
     /*	if(empty($_REQUEST['status']) || $_REQUEST['status'] == 'off'){
     		$focus->status = 0;	
     	}else{
     		$focus->status= 1;
     	}
     	
     	echo "post length:".count($_POST); 
         echo "product_count:".$count."<br>";
     	echo "cost_price num:".count($_POST["cost_price"])."<br";*/
     $return_id = $focus->save();
     /*$quoteLine1 = new QuoteLine();
     	$quoteLine1->mark_deletedByQuoteid($return_id);
     	$count = count($_POST);
     	$keys = array_keys($_POST);
     	$sum = 0;
     	for($i = 0;$i< $count; $i++) {
     		//echo $keys[$i]."<br>";
     		if(substr_count($keys[$i],"productid_") > 0) {
     			$index = substr($keys[$i],strpos($keys[$i],"_")+1);
     			$product_id = $_POST["productid_".$index];
     			
     			if(!isset($product_id) || empty($product_id))
     				continue;
     			
     			$product_name = $_POST["productname_".$index];
     			$product_num = $_POST["productnum_".$index];
                 $pages = $_POST["pages_".$index];
      			$quantity = $_POST["quantity_".$index];
                 $estp = $_POST["estp_".$index];
                 $price = $_POST["price_".$index];     
                 
     			$quoteLine = new QuoteLine();
                 $quoteLine->price = $price;
                 $quoteLine->estp = $estp;
                 $quoteLine->productid = $product_id;
                 $quoteLine->productname = $product_name;
                 $quoteLine->productnum = $product_num;
                 $quoteLine->pages = $pages;
     			$quoteLine->quantity = $quantity;
     			$quoteLine->quoteid = $return_id;
     			$quoteLine->save();
     		}
     	}
     	$count = $_POST["product_count"];*/
     /*	$component = new ProductComponents;
     	$component->retrieve($sugarbean->component_id);
     	$component->status_update('quoted', $component->id);*/
     //	$GLOBLES['log']->debug("Saved record with id of ".$return_id);
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
     $productstatus = new ProductStatus();
     if (isset($_REQUEST['status_action']) && !empty($_REQUEST['status_action'])) {
         $productstatus->update_product_status($_REQUEST['status_action'], $focus, $old_status);
     } else {
         $productstatus->update_product_status($_REQUEST['status'], $focus, $old_status);
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false, $useSiteURL = false, $entryPoint = 'download', $useUploadFolder = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize;
     global $mod_strings;
     global $sugar_config;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     //process the text only flag
     if (isset($_POST['text_only']) && $_POST['text_only'] == '1') {
         $focus->text_only = 1;
     } else {
         $focus->text_only = 0;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $this->handleAttachmentsProcessImages($focus, $redirect, $useSiteURL, $entryPoint, $useUploadFolder);
     return $focus;
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $theme, $current_user;
     $theme_path = "themes/" . $theme . "/";
     require_once 'modules/Contacts/Contact.php';
     require_once $theme_path . 'layout_utils.php';
     require_once 'include/utils.php';
     require_once 'include/formbase.php';
     require_once 'XTemplate/xtpl.php';
     global $timedate;
     $focus = new Contact();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!empty($_POST[$prefix . 'new_reports_to_id'])) {
         $focus->retrieve($_POST[$prefix . 'new_reports_to_id']);
         $focus->reports_to_id = $_POST[$prefix . 'record'];
     } else {
         $focus = populateFromPost($prefix, $focus);
         if (isset($focus->portal_password) && $focus->portal_password != $_POST[$prefix . 'old_portal_password']) {
             $focus->portal_password = md5($focus->portal_password);
         }
         if (!isset($_POST[$prefix . 'email_opt_out'])) {
             $focus->email_opt_out = 'off';
         }
         if (!isset($_POST[$prefix . 'do_not_call'])) {
             $focus->do_not_call = 'off';
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if ($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect') {
         if (isset($_POST[$prefix . 'sync_contact'])) {
             $focus->contacts_users_id = $current_user->id;
         } else {
             if (!isset($focus->users)) {
                 $focus->load_relationship('user_sync');
             }
             $focus->contacts_users_id = null;
             $focus->user_sync->delete($focus->id, $current_user->id);
         }
     }
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateContacts = $this->checkForDuplicates($prefix);
         if (isset($duplicateContacts)) {
             $get = 'module=Contacts&action=ShowDuplicates';
             if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
                 $get .= '&inbound_email_id=' . $_POST['inbound_email_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Contacts{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Contacts{$field}=" . urlencode($focus->{$field});
                 }
             }
             //create list of suspected duplicate contact id's in redirect get string
             $i = 0;
             foreach ($duplicateContacts as $contact) {
                 $get .= "&duplicate[{$i}]=" . $contact['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= "&return_module=";
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= "Contacts";
             }
             $get .= "&return_action=";
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             } else {
                 $get .= "DetailView";
             }
             if (!empty($_POST['return_id'])) {
                 $get .= "&return_id=" . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             // for InboundEmail flow
             if (!empty($_POST['start'])) {
                 $get .= '&start=' . $_POST['start'];
             }
             //now redirect the post to modules/Contacts/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $get));
             } else {
                 if (!empty($_POST['to_pdf'])) {
                     $get .= '&to_pdf=' . $_POST['to_pdf'];
                 }
                 header("Location: index.php?{$get}");
             }
             return null;
         }
     }
     global $current_user;
     if (is_admin($current_user)) {
         if (!isset($_POST[$prefix . 'portal_active'])) {
             $focus->portal_active = '0';
         }
         //if no password is set set account to inactive for portal
         if (empty($_POST[$prefix . 'portal_name'])) {
             $focus->portal_active = '0';
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         // fake this case like it's already saved.
         $focus->save($check_notify);
         require_once 'modules/Emails/Email.php';
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Contacts';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('contacts');
         $email->contacts->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Contacts';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&first_name=' . $focus->first_name;
         $get .= '&last_name=' . $focus->last_name;
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/PurchaseOrders/PurchaseOrder.php';
     require_once 'modules/PurchaseOrderLines/PurchaseOrderLine.php';
     require_once 'log4php/LoggerManager.php';
     require_once 'include/formbase.php';
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $focus = new PurchaseOrder();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) {
         ACLController::displayNoAccess(true);
     }
     if (empty($_REQUEST['status']) || $_REQUEST['status'] == 'off') {
         $focus->status = 0;
     } else {
         $focus->status = 1;
     }
     //echo "post length:".count($_POST);
     //echo "product_count:".$count."<br>";
     //echo "cost_price num:".count($_POST["cost_price"])."<br";
     $return_id = $focus->save();
     $purchaseorderLine1 = new PurchaseOrderLine();
     $purchaseorderLine1->mark_deletedByPurchaseOrderid($return_id);
     $count = count($_POST);
     $keys = array_keys($_POST);
     $sum = 0;
     for ($i = 0; $i < $count; $i++) {
         if (substr_count($keys[$i], "materialname_") > 0) {
             $index = substr($keys[$i], strpos($keys[$i], "_") + 1);
             $materialid = $_POST["materialid_" . $index];
             $paperid = $_POST["paperid_" . $index];
             if (!isset($materialid) || empty($materialid) && !isset($paperid) && empty($paperid)) {
                 continue;
             }
             $number = $_POST["number_" . $index];
             $materialname = $_POST["materialname_" . $index];
             $measure = $_POST["measure_" . $index];
             $unit = $_POST["unit_" . $index];
             $singlep = $_POST["singlep_" . $index];
             $price = $_POST["price_" . $index];
             $purchaseorderLine = new PurchaseOrderLine();
             $purchaseorderLine->number = $number;
             $purchaseorderLine->materialid = $materialid;
             $purchaseorderLine->paperid = $paperid;
             $purchaseorderLine->materialname = $materialname;
             $purchaseorderLine->measure = $measure;
             $purchaseorderLine->unit = $unit;
             $purchaseorderLine->singlep = $singlep;
             $purchaseorderLine->price = $price;
             $purchaseorderLine->purchaseorderid = $return_id;
             $purchaseorderLine->save();
         }
     }
     $count = $_POST["product_count"];
     //	$GLOBLES['log']->debug("Saved record with id of ".$return_id);
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
 /**
  * handles save functionality for meetings
  * @param	string prefix
  * @param	bool redirect default True
  * @param	bool useRequired default True
  */
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     global $current_user;
     global $timedate;
     $focus = BeanFactory::getBean('Meetings');
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!isset($_POST['reminder_checked']) or isset($_POST['reminder_checked']) && $_POST['reminder_checked'] == '0') {
         $_POST['reminder_time'] = -1;
     }
     if (!isset($_POST['reminder_time'])) {
         $_POST['reminder_time'] = $current_user->getPreference('reminder_time');
         $_POST['reminder_checked'] = 1;
     }
     if (!isset($_POST['email_reminder_checked']) || isset($_POST['email_reminder_checked']) && $_POST['email_reminder_checked'] == '0') {
         $_POST['email_reminder_time'] = -1;
     }
     if (!isset($_POST['email_reminder_time'])) {
         $_POST['email_reminder_time'] = $current_user->getPreference('email_reminder_time');
         $_POST['email_reminder_checked'] = 1;
     }
     if (isset($_POST['repeat_parent_id']) && trim($_POST['repeat_parent_id']) == '') {
         unset($_POST['repeat_parent_id']);
     }
     // don't allow to set recurring_source from a form
     unset($_POST['recurring_source']);
     $time_format = $timedate->get_user_time_format();
     $time_separator = ":";
     if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
         $time_separator = $match[1];
     }
     if (!empty($_POST[$prefix . 'time_hour_start']) && empty($_POST['time_start'])) {
         $_POST[$prefix . 'time_start'] = $_POST[$prefix . 'time_hour_start'] . $time_separator . $_POST[$prefix . 'time_minute_start'];
     }
     if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) {
         $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(), $_POST[$prefix . 'meridiem']);
     }
     if (isset($_POST[$prefix . 'time_start']) && strlen($_POST[$prefix . 'date_start']) == 10) {
         $_POST[$prefix . 'date_start'] = $_POST[$prefix . 'date_start'] . ' ' . $_POST[$prefix . 'time_start'];
     }
     // retrieve happens here
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     // if dates changed
     if (!empty($focus->id)) {
         $oldBean = new Meeting();
         $oldBean->retrieve($focus->id);
         if ($focus->date_start != $oldBean->date_start || $focus->date_end != $oldBean->date_end) {
             $focus->date_changed = true;
         } else {
             $focus->date_changed = false;
         }
     }
     $newBean = true;
     if (!empty($focus->id)) {
         $newBean = false;
     }
     //add assigned user and current user if this is the first time bean is saved
     if (empty($focus->id) && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Meetings' && !empty($_REQUEST['return_action']) && $_REQUEST['return_action'] == 'DetailView') {
         //if return action is set to detail view and return module to meeting, then this is from the long form, do not add the assigned user (only the current user)
         //The current user is already added to UI and we want to give the current user the option of opting out of meeting.
         //add current user if the assigned to user is different than current user.
         if ($current_user->id != $_POST['assigned_user_id']) {
             $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', ';
             $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
         }
     } elseif (empty($focus->id)) {
         //this is not from long form so add assigned and current user automatically as there is no invitee list UI.
         //This call could be through an ajax call from subpanels or shortcut bar
         if (!isset($_POST['user_invitees'])) {
             $_POST['user_invitees'] = '';
         }
         $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', ';
         //add current user if the assigned to user is different than current user.
         if ($current_user->id != $_POST['assigned_user_id'] && $_REQUEST['module'] != "Calendar") {
             $_POST['user_invitees'] .= ',' . $current_user->id . ', ';
         }
         //remove any double comma's introduced during appending
         $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
     }
     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'])) {
         $focus->save(true);
         $return_id = $focus->id;
     } else {
         if ($focus->status == 'Held' && $this->isEmptyReturnModuleAndAction() && !$this->isSaveFromDCMenu()) {
             //if we are closing the meeting, and the request does not have a return module AND return action set and it is not a save
             //being triggered by the DCMenu (shortcut bar) then the request is coming from a dashlet or subpanel close icon and there is no
             //need to process user invitees, just save the current values.
             $focus->save(true);
         } else {
             $relate_to = $this->getRelatedModuleName($focus);
             $userInvitees = array();
             $contactInvitees = array();
             $leadInvitees = array();
             $existingUsers = array();
             $existingContacts = array();
             $existingLeads = array();
             if (!empty($_POST['user_invitees'])) {
                 $userInvitees = explode(',', trim($_POST['user_invitees'], ','));
             }
             if (!empty($_POST['existing_invitees'])) {
                 $existingUsers = explode(",", trim($_POST['existing_invitees'], ','));
             }
             if (!empty($_POST['contact_invitees'])) {
                 $contactInvitees = explode(',', trim($_POST['contact_invitees'], ','));
             }
             if (!empty($_POST['existing_contact_invitees'])) {
                 $existingContacts = explode(",", trim($_POST['existing_contact_invitees'], ','));
             }
             if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
                 $contactInvitees[] = $_POST['parent_id'];
             }
             if ($relate_to == 'Contacts') {
                 if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_id'], $contactInvitees)) {
                     $contactInvitees[] = $_REQUEST['relate_id'];
                 }
             }
             if (!empty($_POST['lead_invitees'])) {
                 $leadInvitees = explode(',', trim($_POST['lead_invitees'], ','));
             }
             if (!empty($_POST['existing_lead_invitees'])) {
                 $existingLeads = explode(",", trim($_POST['existing_lead_invitees'], ','));
             }
             if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') {
                 $leadInvitees[] = $_POST['parent_id'];
             }
             if ($relate_to == 'Leads') {
                 if (!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_id'], $leadInvitees)) {
                     $leadInvitees[] = $_REQUEST['relate_id'];
                 }
             }
             // Call the Meeting module's save function to handle saving other fields besides
             // the users and contacts relationships
             $focus->update_vcal = false;
             // Bug #49195 : don't update vcal b/s related users aren't saved yet, create vcal cache below
             $focus->users_arr = $userInvitees;
             $focus->contacts_arr = $contactInvitees;
             $focus->leads_arr = $leadInvitees;
             $focus->save(true);
             $return_id = $focus->id;
             if (empty($return_id)) {
                 //this is to handle the situation where the save fails, most likely because of a failure
                 //in the external api. bug: 42200
                 $_REQUEST['action'] = 'EditView';
                 $_REQUEST['return_action'] = 'EditView';
                 handleRedirect('', 'Meetings');
             }
             $focus->setUserInvitees($userInvitees, $existingUsers);
             $focus->setContactInvitees($contactInvitees, $existingContacts);
             $focus->setLeadInvitees($focus->leads_arr, $existingLeads);
             // Bug #49195 : update vcal
             vCal::cache_sugar_vcal($current_user);
             $this->processRecurring($focus);
         }
     }
     if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] === 'Home') {
         SugarApplication::redirect(buildRedirectURL('', 'Home'));
     } else {
         if ($redirect) {
             handleRedirect($return_id, 'Meetings');
         } else {
             return $focus;
         }
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize;
     global $mod_strings;
     global $sugar_config;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     //process the text only flag
     if (isset($_POST['text_only']) && $_POST['text_only'] == '1') {
         $focus->text_only = 1;
     } else {
         $focus->text_only = 0;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $preProcessedImages = array();
     $emailTemplateBodyHtml = from_html($focus->body_html);
     if (strpos($emailTemplateBodyHtml, '"cache/images/')) {
         $matches = array();
         preg_match_all('#<img[^>]*[\\s]+src[^=]*=[\\s]*["\']cache/images/(.+?)["\']#si', $emailTemplateBodyHtml, $matches);
         foreach ($matches[1] as $match) {
             $filename = urldecode($match);
             $file_location = sugar_cached("images/{$filename}");
             $mime_type = pathinfo($filename, PATHINFO_EXTENSION);
             if (file_exists($file_location)) {
                 $id = create_guid();
                 $newFileLocation = "upload://{$id}";
                 if (!copy($file_location, $newFileLocation)) {
                     $GLOBALS['log']->debug("EMAIL Template could not copy attachment to {$newFileLocation}");
                 } else {
                     $secureLink = "index.php?entryPoint=download&type=Notes&id={$id}";
                     $emailTemplateBodyHtml = str_replace("cache/images/{$match}", $secureLink, $emailTemplateBodyHtml);
                     unlink($file_location);
                     $preProcessedImages[$filename] = $id;
                 }
             }
             // if
         }
         // foreach
     }
     // if
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     $focus->body_html = $emailTemplateBodyHtml;
     $return_id = $focus->save($check_notify);
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = count($_FILES);
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     //for($i = 0; $i < $max_files_upload; $i++) {
     foreach ($_FILES as $key => $file) {
         $note = new Note();
         //Images are presaved above so we need to prevent duplicate files from being created.
         if (isset($preProcessedImages[$file['name']])) {
             $oldId = $preProcessedImages[$file['name']];
             $note->id = $oldId;
             $note->new_with_id = TRUE;
             $GLOBALS['log']->debug("Image {$file['name']} has already been processed.");
         }
         $i = preg_replace("/email_attachment(.+)/", '$1', $key);
         $upload_file = new UploadFile($key);
         if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) {
                 if ($_REQUEST['embedded' . $i] == 'true') {
                     $note->embed_flag = true;
                 } else {
                     $note->embed_flag = false;
                 }
             }
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id) && $note->new_with_id === FALSE) {
             if (empty($_REQUEST['old_id'])) {
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNote->date_modified = '';
                 $newNote->date_entered = '';
                 $newNoteId = $newNote->save();
                 UploadFile::duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         array_push($focus->saved_attachments, $note);
         $note->id = $note_id;
         if ($note->new_with_id === FALSE) {
             $note->file->final_move($note->id);
         } else {
             $GLOBALS['log']->debug("Not performing final move for note id {$note->id} as it has already been processed");
         }
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     $count = '';
     //_pp($_REQUEST);
     //_ppd(count($_REQUEST['document']));
     if (!empty($_REQUEST['document'])) {
         $count = count($_REQUEST['document']);
     } else {
         $count = 10;
     }
     for ($i = 0; $i < $count; $i++) {
         if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) {
             $doc = new Document();
             $docRev = new DocumentRevision();
             $docNote = new Note();
             $doc->retrieve($_REQUEST['documentId' . $i]);
             $docRev->retrieve($doc->document_revision_id);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->id;
             $docNote->parent_type = 'Emails';
             $docNote->file_mime_type = $docRev->file_mime_type;
             $docId = $docNote = $docNote->save();
             UploadFile::duplicate_file($docRev->id, $docId, $docRev->filename);
         }
     }
     ////	END ATTACHMENTS FROM DOCUMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	REMOVE ATTACHMENTS
     if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) {
         foreach ($_REQUEST['remove_attachment'] as $noteId) {
             $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     clear_register_value('select_array', $focus->object_name);
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     $focus = new ProspectList();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (empty($focus->name)) {
         return null;
     }
     if (!isset($focus->assigned_user_id) || $focus->assigned_user_id == '') {
         $focus->assigned_user_id = $GLOBALS['current_user']->id;
     }
     $return_id = $focus->save();
     if ($redirect) {
         Log::debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "ProspectLists");
     } else {
         return $focus;
     }
 }
Exemple #19
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $do_save = true, $exist_lead = null)
 {
     require_once 'modules/Campaigns/utils.php';
     require_once 'include/formbase.php';
     if (empty($exist_lead)) {
         $focus = new Lead();
     } else {
         $focus = $exist_lead;
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_POST[$prefix . 'email_opt_out'])) {
         $focus->email_opt_out = 0;
     }
     if (!isset($_POST[$prefix . 'do_not_call'])) {
         $focus->do_not_call = 0;
     }
     if ($do_save) {
         if (!empty($GLOBALS['check_notify'])) {
             $focus->save($GLOBALS['check_notify']);
         } else {
             $focus->save(FALSE);
         }
     }
     $return_id = $focus->id;
     if (isset($_POST[$prefix . 'prospect_id']) && !empty($_POST[$prefix . 'prospect_id'])) {
         $prospect = new Prospect();
         $prospect->retrieve($_POST[$prefix . 'prospect_id']);
         $prospect->lead_id = $focus->id;
         $prospect->save();
         //if prospect id exists, make sure we are coming from prospect detail
         if (strtolower($_POST['return_module']) == 'prospects' && strtolower($_POST['return_action']) == 'detailview') {
             //create campaing_log entry
             if (isset($focus->campaign_id) && $focus->campaign_id != null) {
                 campaign_log_lead_entry($focus->campaign_id, $prospect, $focus, 'lead');
             }
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         if (!isset($current_user)) {
             global $current_user;
         }
         // fake this case like it's already saved.
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Leads';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('leads');
         $email->leads->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start']);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, 'Leads');
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     require_once 'include/upload_file.php';
     global $upload_maxsize, $upload_dir;
     global $mod_strings;
     global $sugar_config;
     $focus = new EmailTemplate();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     //process the text only flag
     if (isset($_POST['text_only']) && $_POST['text_only'] == '1') {
         $focus->text_only = 1;
     } else {
         $focus->text_only = 0;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if (!isset($_REQUEST['published'])) {
         $focus->published = 'off';
     }
     $emailTemplateBodyHtml = from_html($focus->body_html);
     $fileBasePath = "{$sugar_config['cache_dir']}images/";
     $filePatternSearch = "{$sugar_config['cache_dir']}";
     $filePatternSearch = str_replace("/", "\\/", $filePatternSearch);
     $filePatternSearch = $filePatternSearch . "images\\/";
     $fileBasePath1 = "\"" . $fileBasePath;
     if (strpos($emailTemplateBodyHtml, "\"{$fileBasePath}")) {
         $matches = array();
         preg_match_all("/{$filePatternSearch}.+?\"/i", $emailTemplateBodyHtml, $matches);
         foreach ($matches[0] as $match) {
             $filenameUndecoded = str_replace($fileBasePath, '', $match);
             $filename = urldecode(substr($filenameUndecoded, 0, -1));
             $filenameUndecoded = str_replace("\"", '', $filenameUndecoded);
             $cid = $filename;
             $file_location = clean_path(getcwd() . "/{$sugar_config['cache_dir']}images/{$filename}");
             $mime_type = strtolower(substr($filename, strrpos($filename, ".") + 1, strlen($filename)));
             if (file_exists($file_location)) {
                 $id = create_guid();
                 $newFileLocation = "{$sugar_config['upload_dir']}{$id}.{$mime_type}";
                 if (!copy($file_location, $newFileLocation)) {
                     $GLOBALS['log']->debug("EMAIL Template could not copy attachment to {$sugar_config['upload_dir']} [ {$newFileLocation} ]");
                 } else {
                     $emailTemplateBodyHtml = str_replace("{$sugar_config['cache_dir']}images/{$filenameUndecoded}", $newFileLocation, $emailTemplateBodyHtml);
                     unlink($file_location);
                 }
             }
             // if
         }
         // foreach
     }
     // if
     $focus->body_html = $emailTemplateBodyHtml;
     $return_id = $focus->save();
     ///////////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////
     ////	ADDING NEW ATTACHMENTS
     $max_files_upload = count($_FILES);
     if (!empty($focus->id)) {
         $note = new Note();
         $where = "notes.parent_id='{$focus->id}'";
         if (!empty($_REQUEST['old_id'])) {
             // to support duplication of email templates
             $where .= " OR notes.parent_id='" . $_REQUEST['old_id'] . "'";
         }
         $notes_list = $note->get_full_list("", $where, true);
     }
     if (!isset($notes_list)) {
         $notes_list = array();
     }
     if (!is_array($focus->attachments)) {
         // PHP5 does not auto-create arrays(). Need to initialize it here.
         $focus->attachments = array();
     }
     $focus->attachments = array_merge($focus->attachments, $notes_list);
     //for($i = 0; $i < $max_files_upload; $i++) {
     foreach ($_FILES as $key => $file) {
         $note = new Note();
         $i = preg_replace("/email_attachment(.+)/", '$1', $key);
         $upload_file = new UploadFile($key);
         if ($upload_file == -1) {
             continue;
         }
         if (isset($_FILES[$key]) && $upload_file->confirm_upload() && preg_match("/^email_attachment/", $key)) {
             $note->filename = $upload_file->get_stored_file_name();
             $note->file = $upload_file;
             $note->name = $mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ' . $note->file->original_file_name;
             if (isset($_REQUEST['embedded' . $i]) && !empty($_REQUEST['embedded' . $i])) {
                 if ($_REQUEST['embedded' . $i] == 'true') {
                     $note->embed_flag = true;
                 } else {
                     $note->embed_flag = false;
                 }
             }
             array_push($focus->attachments, $note);
         }
     }
     $focus->saved_attachments = array();
     foreach ($focus->attachments as $note) {
         if (!empty($note->id)) {
             if (empty($_REQUEST['old_id'])) {
                 // to support duplication of email templates
                 array_push($focus->saved_attachments, $note);
             } else {
                 // we're duplicating a template with attachments
                 // dupe the file, create a new note, assign the note to the new template
                 $newNote = new Note();
                 $newNote->retrieve($note->id);
                 $newNote->id = create_guid();
                 $newNote->parent_id = $focus->id;
                 $newNote->new_with_id = true;
                 $newNote->date_modified = '';
                 $newNote->date_entered = '';
                 $newNoteId = $newNote->save();
                 $dupeFile = new UploadFile('duplicate');
                 $dupeFile->duplicate_file($note->id, $newNoteId, $note->filename);
             }
             continue;
         }
         $note->parent_id = $focus->id;
         $note->parent_type = 'Emails';
         $note->file_mime_type = $note->file->mime_type;
         $note_id = $note->save();
         array_push($focus->saved_attachments, $note);
         $note->id = $note_id;
         $note->file->final_move($note->id);
     }
     ////	END NEW ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS FROM DOCUMENTS
     $count = '';
     //_pp($_REQUEST);
     //_ppd(count($_REQUEST['document']));
     if (!empty($_REQUEST['document'])) {
         $count = count($_REQUEST['document']);
     } else {
         $count = 10;
     }
     for ($i = 0; $i < $count; $i++) {
         if (isset($_REQUEST['documentId' . $i]) && !empty($_REQUEST['documentId' . $i])) {
             $doc = new Document();
             $docRev = new DocumentRevision();
             $docNote = new Note();
             $noteFile = new UploadFile('none');
             $doc->retrieve($_REQUEST['documentId' . $i]);
             $docRev->retrieve($doc->document_revision_id);
             array_push($focus->saved_attachments, $docRev);
             $docNote->name = $doc->document_name;
             $docNote->filename = $docRev->filename;
             $docNote->description = $doc->description;
             $docNote->parent_id = $focus->id;
             $docNote->parent_type = 'Emails';
             $docNote->file_mime_type = $docRev->file_mime_type;
             $docId = $docNote = $docNote->save();
             $noteFile->duplicate_file($docRev->id, $docId, $docRev->filename);
         }
     }
     ////	END ATTACHMENTS FROM DOCUMENTS
     ///////////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////
     ////	REMOVE ATTACHMENTS
     if (isset($_REQUEST['remove_attachment']) && !empty($_REQUEST['remove_attachment'])) {
         foreach ($_REQUEST['remove_attachment'] as $noteId) {
             $q = 'UPDATE notes SET deleted = 1 WHERE id = \'' . $noteId . '\'';
             $focus->db->query($q);
         }
     }
     ////	END REMOVE ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////////
     ////	END ATTACHMENT HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if ($redirect) {
         $GLOBALS['log']->debug("Saved record with id of " . $return_id);
         handleRedirect($return_id, "EmailTemplates");
     } else {
         return $focus;
     }
 }
Exemple #21
0
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     $focus = new xVendor();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicatexVendors = $this->checkForDuplicates($prefix);
         if (isset($duplicatexVendors)) {
             $location = 'module=xVendors&action=ShowDuplicates';
             $get = '';
             // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&xVendorsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&xVendorsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&xVendors{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&xVendors{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&xVendors{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate xvendor id's in redirect get string
             $i = 0;
             foreach ($duplicatexVendors as $xvendor) {
                 $get .= "&duplicate[{$i}]=" . $xvendor['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= '&return_module=';
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= 'xVendors';
             }
             $get .= '&return_action=';
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             //else $get .= 'DetailView';
             if (!empty($_POST['return_id'])) {
                 $get .= '&return_id=' . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             //now redirect the post to modules/xVendors/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         $trackerManager = TrackerManager::getInstance();
         $timeStamp = TimeDate::getInstance()->nowDb();
         if ($monitor = $trackerManager->getMonitor('tracker')) {
             $monitor->setValue('action', 'detailview');
             $monitor->setValue('user_id', $GLOBALS['current_user']->id);
             $monitor->setValue('module_name', 'xVendors');
             $monitor->setValue('date_modified', $timeStamp);
             $monitor->setValue('visible', 1);
             if (!empty($this->bean->id)) {
                 $monitor->setValue('item_id', $return_id);
                 $monitor->setValue('item_summary', $focus->get_summary_text());
             }
             $trackerManager->saveMonitor($monitor, true, true);
         }
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'xVendors';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&name=' . $focus->name;
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         handleRedirect($return_id, 'xVendors');
     } else {
         return $focus;
     }
 }
Exemple #22
0
 /**
  * handles save functionality for meetings
  * @param	string prefix
  * @param	bool redirect default True
  * @param	bool useRequired default True
  */
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     global $current_user;
     global $timedate;
     $focus = new Meeting();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!isset($_POST['reminder_checked']) or isset($_POST['reminder_checked']) && $_POST['reminder_checked'] == '0') {
         $_POST['reminder_time'] = -1;
     }
     if (!isset($_POST['reminder_time'])) {
         $_POST['reminder_time'] = $current_user->getPreference('reminder_time');
         $_POST['reminder_checked'] = 1;
     }
     if (!isset($_POST['email_reminder_checked']) || isset($_POST['email_reminder_checked']) && $_POST['email_reminder_checked'] == '0') {
         $_POST['email_reminder_time'] = -1;
     }
     if (!isset($_POST['email_reminder_time'])) {
         $_POST['email_reminder_time'] = $current_user->getPreference('email_reminder_time');
         $_POST['email_reminder_checked'] = 1;
     }
     // don't allow to set recurring_source from a form
     unset($_POST['recurring_source']);
     $time_format = $timedate->get_user_time_format();
     $time_separator = ":";
     if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
         $time_separator = $match[1];
     }
     if (!empty($_POST[$prefix . 'time_hour_start']) && empty($_POST['time_start'])) {
         $_POST[$prefix . 'time_start'] = $_POST[$prefix . 'time_hour_start'] . $time_separator . $_POST[$prefix . 'time_minute_start'];
     }
     if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) {
         $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(), $_POST[$prefix . 'meridiem']);
     }
     if (isset($_POST[$prefix . 'time_start']) && strlen($_POST[$prefix . 'date_start']) == 10) {
         $_POST[$prefix . 'date_start'] = $_POST[$prefix . 'date_start'] . ' ' . $_POST[$prefix . 'time_start'];
     }
     // retrieve happens here
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     // if dates changed
     if (!empty($focus->id)) {
         $oldBean = new Meeting();
         $oldBean->retrieve($focus->id);
         if ($focus->date_start != $oldBean->date_start || $focus->date_end != $oldBean->date_end) {
             $focus->date_changed = true;
         } else {
             $focus->date_changed = false;
         }
     }
     $newBean = true;
     if (!empty($focus->id)) {
         $newBean = false;
     }
     //add assigned user and current user if this is the first time bean is saved
     if (empty($focus->id) && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Meetings' && !empty($_REQUEST['return_action']) && $_REQUEST['return_action'] == 'DetailView') {
         //if return action is set to detail view and return module to meeting, then this is from the long form, do not add the assigned user (only the current user)
         //The current user is already added to UI and we want to give the current user the option of opting out of meeting.
         //add current user if the assigned to user is different than current user.
         if ($current_user->id != $_POST['assigned_user_id']) {
             $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', ';
             $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
         }
     } elseif (empty($focus->id)) {
         //this is not from long form so add assigned and current user automatically as there is no invitee list UI.
         //This call could be through an ajax call from subpanels or shortcut bar
         if (!isset($_POST['user_invitees'])) {
             $_POST['user_invitees'] = '';
         }
         $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', ';
         //add current user if the assigned to user is different than current user.
         if ($current_user->id != $_POST['assigned_user_id'] && $_REQUEST['module'] != "Calendar") {
             $_POST['user_invitees'] .= ',' . $current_user->id . ', ';
         }
         //remove any double comma's introduced during appending
         $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
     }
     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'])) {
         $focus->save(true);
         $return_id = $focus->id;
     } else {
         if ($focus->status == 'Held' && $this->isEmptyReturnModuleAndAction() && !$this->isSaveFromDCMenu()) {
             //if we are closing the meeting, and the request does not have a return module AND return action set and it is not a save
             //being triggered by the DCMenu (shortcut bar) then the request is coming from a dashlet or subpanel close icon and there is no
             //need to process user invitees, just save the current values.
             $focus->save(true);
         } else {
             ///////////////////////////////////////////////////////////////////////////
             ////	REMOVE INVITEE RELATIONSHIPS
             if (!empty($_POST['user_invitees'])) {
                 $userInvitees = explode(',', trim($_POST['user_invitees'], ','));
             } else {
                 $userInvitees = array();
             }
             // Calculate which users to flag as deleted and which to add
             $deleteUsers = array();
             $focus->load_relationship('users');
             // Get all users for the meeting
             $q = 'SELECT mu.user_id, mu.accept_status FROM meetings_users mu WHERE mu.meeting_id = \'' . $focus->id . '\' AND mu.deleted=0';
             $r = $focus->db->query($q);
             $acceptStatusUsers = array();
             while ($a = $focus->db->fetchByAssoc($r)) {
                 if (!in_array($a['user_id'], $userInvitees)) {
                     $deleteUsers[$a['user_id']] = $a['user_id'];
                 } else {
                     $acceptStatusUsers[$a['user_id']] = $a['accept_status'];
                 }
             }
             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 meetings_users set deleted = 1 where user_id in ({$sql}) AND meeting_id = '" . $focus->id . "'";
                 $focus->db->query($sql);
             }
             // Get all contacts for the meeting
             if (!empty($_POST['contact_invitees'])) {
                 $contactInvitees = explode(',', trim($_POST['contact_invitees'], ','));
             } else {
                 $contactInvitees = array();
             }
             $deleteContacts = array();
             $focus->load_relationship('contacts');
             $q = 'SELECT mu.contact_id, mu.accept_status FROM meetings_contacts mu WHERE mu.meeting_id = \'' . $focus->id . '\' AND mu.deleted=0';
             $r = $focus->db->query($q);
             $acceptStatusContacts = array();
             while ($a = $focus->db->fetchByAssoc($r)) {
                 if (!in_array($a['contact_id'], $contactInvitees)) {
                     $deleteContacts[$a['contact_id']] = $a['contact_id'];
                 } else {
                     $acceptStatusContacts[$a['contact_id']] = $a['accept_status'];
                 }
             }
             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 meetings_contacts set deleted = 1 where contact_id in ({$sql}) AND meeting_id = '" . $focus->id . "'";
                 $focus->db->query($sql);
             }
             if (!empty($_POST['lead_invitees'])) {
                 $leadInvitees = explode(',', trim($_POST['lead_invitees'], ','));
             } else {
                 $leadInvitees = array();
             }
             $deleteLeads = array();
             $focus->load_relationship('leads');
             $q = 'SELECT mu.lead_id, mu.accept_status FROM meetings_leads mu WHERE mu.meeting_id = \'' . $focus->id . '\' AND mu.deleted=0';
             $r = $focus->db->query($q);
             $acceptStatusLeads = array();
             while ($a = $focus->db->fetchByAssoc($r)) {
                 if (!in_array($a['lead_id'], $leadInvitees)) {
                     $deleteLeads[$a['lead_id']] = $a['lead_id'];
                 } else {
                     $acceptStatusLeads[$a['lead_id']] = $a['accept_status'];
                 }
             }
             if (count($deleteLeads) > 0) {
                 $sql = '';
                 foreach ($deleteLeads 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 meetings_leads set deleted = 1 where lead_id in ({$sql}) AND meeting_id = '" . $focus->id . "'";
                 $focus->db->query($sql);
             }
             ////	END REMOVE
             ///////////////////////////////////////////////////////////////////////////
             ///////////////////////////////////////////////////////////////////////////
             ////	REBUILD INVITEE RELATIONSHIPS
             $focus->users_arr = array();
             $focus->users_arr = $userInvitees;
             $focus->contacts_arr = array();
             $focus->contacts_arr = $contactInvitees;
             $focus->leads_arr = array();
             $focus->leads_arr = $leadInvitees;
             if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
                 $focus->contacts_arr[] = $_POST['parent_id'];
             }
             if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') {
                 $focus->leads_arr[] = $_POST['parent_id'];
             }
             // Call the Meeting module's save function to handle saving other fields besides
             // the users and contacts relationships
             $focus->update_vcal = false;
             // Bug #49195 : don't update vcal b/s related users aren't saved yet, create vcal cache below
             $focus->save(true);
             $return_id = $focus->id;
             if (empty($return_id)) {
                 //this is to handle the situation where the save fails, most likely because of a failure
                 //in the external api. bug: 42200
                 $_REQUEST['action'] = 'EditView';
                 $_REQUEST['return_action'] = 'EditView';
                 handleRedirect('', 'Meetings');
             }
             // Process users
             $existing_users = array();
             if (!empty($_POST['existing_invitees'])) {
                 $existing_users = explode(",", trim($_POST['existing_invitees'], ','));
             }
             foreach ($focus->users_arr as $user_id) {
                 if (empty($user_id) || isset($existing_users[$user_id]) || isset($deleteUsers[$user_id])) {
                     continue;
                 }
                 if (!isset($acceptStatusUsers[$user_id])) {
                     $focus->users->add($user_id);
                 } else {
                     if (!$focus->date_changed) {
                         // update query to preserve accept_status
                         $qU = 'UPDATE meetings_users SET deleted = 0, accept_status = \'' . $acceptStatusUsers[$user_id] . '\' ';
                         $qU .= 'WHERE meeting_id = \'' . $focus->id . '\' ';
                         $qU .= 'AND user_id = \'' . $user_id . '\'';
                         $focus->db->query($qU);
                     }
                 }
             }
             // Process contacts
             $existing_contacts = array();
             if (!empty($_POST['existing_contact_invitees'])) {
                 $existing_contacts = explode(",", trim($_POST['existing_contact_invitees'], ','));
             }
             foreach ($focus->contacts_arr as $contact_id) {
                 if (empty($contact_id) || isset($existing_contacts[$contact_id]) || isset($deleteContacts[$contact_id])) {
                     continue;
                 }
                 if (!isset($acceptStatusContacts[$contact_id])) {
                     $focus->contacts->add($contact_id);
                 } else {
                     if (!$focus->date_changed) {
                         // update query to preserve accept_status
                         $qU = 'UPDATE meetings_contacts SET deleted = 0, accept_status = \'' . $acceptStatusContacts[$contact_id] . '\' ';
                         $qU .= 'WHERE meeting_id = \'' . $focus->id . '\' ';
                         $qU .= 'AND contact_id = \'' . $contact_id . '\'';
                         $focus->db->query($qU);
                     }
                 }
             }
             // Process leads
             $existing_leads = array();
             if (!empty($_POST['existing_lead_invitees'])) {
                 $existing_leads = explode(",", trim($_POST['existing_lead_invitees'], ','));
             }
             foreach ($focus->leads_arr as $lead_id) {
                 if (empty($lead_id) || isset($existing_leads[$lead_id]) || isset($deleteLeads[$lead_id])) {
                     continue;
                 }
                 if (!isset($acceptStatusLeads[$lead_id])) {
                     $focus->leads->add($lead_id);
                 } else {
                     if (!$focus->date_changed) {
                         // update query to preserve accept_status
                         $qU = 'UPDATE meetings_leads SET deleted = 0, accept_status = \'' . $acceptStatusLeads[$lead_id] . '\' ';
                         $qU .= 'WHERE meeting_id = \'' . $focus->id . '\' ';
                         $qU .= 'AND lead_id = \'' . $lead_id . '\'';
                         $focus->db->query($qU);
                     }
                 }
             }
             // Bug #49195 : update vcal
             vCal::cache_sugar_vcal($current_user);
             // CCL - Comment out call to set $current_user as invitee
             // set organizer to auto-accept
             if ($focus->assigned_user_id == $current_user->id && $newBean) {
                 $focus->set_accept_status($current_user, 'accept');
             }
             ////	END REBUILD INVITEE RELATIONSHIPS
             ///////////////////////////////////////////////////////////////////////////
         }
     }
     if (!empty($_POST['is_ajax_call'])) {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         exit;
     }
     if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Home') {
         header("Location: index.php?module=Home&action=index");
     } else {
         if ($redirect) {
             handleRedirect($return_id, 'Meetings');
         } else {
             return $focus;
         }
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $theme;
     require_once 'include/formbase.php';
     global $timedate;
     $focus = new Prospect();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         return null;
     }
     if (!isset($GLOBALS['check_notify'])) {
         $GLOBALS['check_notify'] = false;
     }
     if (!isset($_POST[$prefix . 'email_opt_out'])) {
         $focus->email_opt_out = 0;
     }
     if (!isset($_POST[$prefix . 'do_not_call'])) {
         $focus->do_not_call = 0;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         /*
         		// we don't check dupes on Prospects - this is the dirtiest data in the system
         		//$duplicateProspects = $this->checkForDuplicates($prefix);
         		if(isset($duplicateProspects)){
         			$get='module=Prospects&action=ShowDuplicates';
         			
         			//add all of the post fields to redirect get string
         			foreach ($focus->column_fields as $field) 
         			{
         				if (!empty($focus->$field))
         				{
         					$get .= "&Prospects$field=".urlencode($focus->$field);
         				}	
         			}
         			
         			foreach ($focus->additional_column_fields as $field) 
         			{
         				if (!empty($focus->$field))
         				{
         					$get .= "&Prospects$field=".urlencode($focus->$field);
         				}	
         			}
         
         			//create list of suspected duplicate prospect id's in redirect get string
         			$i=0;
         			foreach ($duplicateProspects as $prospect)
         			{
         				$get .= "&duplicate[$i]=".$prospect['id'];
         				$i++;
         			}
         
         			//add return_module, return_action, and return_id to redirect get string
         			$get .= "&return_module=";
         			if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
         			else $get .= "Prospects";
         			$get .= "&return_action=";
         			if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
         			else $get .= "DetailView";
         			if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
         
         			//now redirect the post to modules/Prospects/ShowDuplicates.php
         			header("Location: index.php?$get");
         			return null;
         		}*/
     }
     global $current_user;
     $focus->save($GLOBALS['check_notify']);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Prospects';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&first_name=' . $focus->first_name;
         $get .= '&last_name=' . $focus->last_name;
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         require_once 'include/formbase.php';
         handleRedirect($return_id, 'Prospects');
     } else {
         return $focus;
     }
 }
 protected function checkRequired($params, $required = [])
 {
     return checkRequired($params, $required);
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     global $current_user;
     global $timedate;
     //BUG 17418 MFH
     if (isset($_POST[$prefix . 'duration_hours'])) {
         $_POST[$prefix . 'duration_hours'] = trim($_POST[$prefix . 'duration_hours']);
     }
     $focus = new Call();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!isset($_POST[$prefix . 'reminder_checked']) or $_POST[$prefix . 'reminder_checked'] == 0) {
         $GLOBALS['log']->debug(__FILE__ . '(' . __LINE__ . '): No reminder checked, resetting the reminder_time');
         $_POST[$prefix . 'reminder_time'] = -1;
     }
     if (!isset($_POST[$prefix . 'reminder_time'])) {
         $GLOBALS['log']->debug(__FILE__ . '(' . __LINE__ . '): Getting the users default reminder time');
         $_POST[$prefix . 'reminder_time'] = $current_user->getPreference('reminder_time');
     }
     $time_format = $timedate->get_user_time_format();
     $time_separator = ":";
     if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
         $time_separator = $match[1];
     }
     if (!empty($_POST[$prefix . 'time_hour_start']) && empty($_POST[$prefix . 'time_start'])) {
         $_POST[$prefix . 'time_start'] = $_POST[$prefix . 'time_hour_start'] . $time_separator . $_POST[$prefix . 'time_minute_start'];
     }
     if (isset($_POST[$prefix . 'meridiem']) && !empty($_POST[$prefix . 'meridiem'])) {
         $_POST[$prefix . 'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix . 'time_start'], $timedate->get_time_format(), $_POST[$prefix . 'meridiem']);
     }
     if (isset($_POST[$prefix . 'time_start']) && strlen($_POST[$prefix . 'date_start']) == 10) {
         $_POST[$prefix . 'date_start'] = $_POST[$prefix . 'date_start'] . ' ' . $_POST[$prefix . 'time_start'];
     }
     // retrieve happens here
     $focus = populateFromPost($prefix, $focus);
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     //add assigned user and current user if this is the first time bean is saved
     if (empty($focus->id) && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Calls' && !empty($_REQUEST['return_action']) && $_REQUEST['return_action'] == 'DetailView') {
         //if return action is set to detail view and return module to call, then this is from the long form, do not add the assigned user (only the current user)
         //The current user is already added to UI and we want to give the current user the option of opting out of meeting.
         if ($current_user->id != $_POST['assigned_user_id']) {
             $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', ';
             $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
         }
     } elseif (empty($focus->id)) {
         //this is not from long form so add assigned and current user automatically as there is no invitee list UI.
         //This call could be through an ajax call from subpanels or shortcut bar
         $_POST['user_invitees'] .= ',' . $_POST['assigned_user_id'] . ', ';
         //add current user if the assigned to user is different than current user.
         if ($current_user->id != $_POST['assigned_user_id']) {
             $_POST['user_invitees'] .= ',' . $current_user->id . ', ';
         }
         //remove any double comma's introduced during appending
         $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
     }
     if (isset($_POST['isSaveFromDetailView']) && $_POST['isSaveFromDetailView'] == 'true' || isset($_POST['is_ajax_call']) && !empty($_POST['is_ajax_call']) && !empty($focus->id)) {
         $focus->save(true);
         $return_id = $focus->id;
     } else {
         if ($focus->status == 'Held' && $this->isEmptyReturnModuleAndAction() && !$this->isSaveFromDCMenu()) {
             //if we are closing the meeting, and the request does not have a return module AND return action set and it is not a save
             //being triggered by the DCMenu (shortcut bar) then the request is coming from a dashlet or subpanel close icon and there is no
             //need to process user invitees, just save the current values.
             $focus->save(true);
         } else {
             ///////////////////////////////////////////////////////////////////////////
             ////	REMOVE INVITEE RELATIONSHIPS
             if (!empty($_POST['user_invitees'])) {
                 $userInvitees = explode(',', trim($_POST['user_invitees'], ','));
             } else {
                 $userInvitees = array();
             }
             // Calculate which users to flag as deleted and which to add
             $deleteUsers = array();
             $focus->load_relationship('users');
             // Get all users for the call
             $q = 'SELECT mu.user_id, mu.accept_status FROM calls_users mu WHERE mu.call_id = \'' . $focus->id . '\'';
             $r = $focus->db->query($q);
             $acceptStatusUsers = array();
             while ($a = $focus->db->fetchByAssoc($r)) {
                 if (!in_array($a['user_id'], $userInvitees)) {
                     $deleteUsers[$a['user_id']] = $a['user_id'];
                 } else {
                     $acceptStatusUsers[$a['user_id']] = $a['accept_status'];
                 }
             }
             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 calls_users set deleted = 1 where user_id in ({$sql}) AND call_id = '" . $focus->id . "'";
                 $focus->db->query($sql);
             }
             // Get all contacts for the call
             if (!empty($_POST['contact_invitees'])) {
                 $contactInvitees = explode(',', trim($_POST['contact_invitees'], ','));
             } else {
                 $contactInvitees = array();
             }
             $deleteContacts = array();
             $focus->load_relationship('contacts');
             $q = 'SELECT mu.contact_id, mu.accept_status FROM calls_contacts mu WHERE mu.call_id = \'' . $focus->id . '\'';
             $r = $focus->db->query($q);
             $acceptStatusContacts = array();
             while ($a = $focus->db->fetchByAssoc($r)) {
                 if (!in_array($a['contact_id'], $contactInvitees)) {
                     $deleteContacts[$a['contact_id']] = $a['contact_id'];
                 } else {
                     $acceptStatusContacts[$a['contact_id']] = $a['accept_status'];
                 }
             }
             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 calls_contacts set deleted = 1 where contact_id in ({$sql}) AND call_id = '" . $focus->id . "'";
                 $focus->db->query($sql);
             }
             if (!empty($_POST['lead_invitees'])) {
                 $leadInvitees = explode(',', trim($_POST['lead_invitees'], ','));
             } else {
                 $leadInvitees = array();
             }
             // Calculate which leads to flag as deleted and which to add
             $deleteLeads = array();
             $focus->load_relationship('leads');
             // Get all leads for the call
             $q = 'SELECT mu.lead_id, mu.accept_status FROM calls_leads mu WHERE mu.call_id = \'' . $focus->id . '\'';
             $r = $focus->db->query($q);
             $acceptStatusLeads = array();
             while ($a = $focus->db->fetchByAssoc($r)) {
                 if (!in_array($a['lead_id'], $leadInvitees)) {
                     $deleteLeads[$a['lead_id']] = $a['lead_id'];
                 } else {
                     $acceptStatusLeads[$a['user_id']] = $a['accept_status'];
                 }
             }
             if (count($deleteLeads) > 0) {
                 $sql = '';
                 foreach ($deleteLeads as $u) {
                     // make sure we don't delete the assigned user
                     if ($u != $focus->assigned_user_id) {
                         $sql .= ",'" . $u . "'";
                     }
                 }
                 $sql = substr($sql, 1);
                 // We could run a delete SQL statement here, but will just mark as deleted instead
                 $sql = "UPDATE calls_leads set deleted = 1 where lead_id in ({$sql}) AND call_id = '" . $focus->id . "'";
                 $focus->db->query($sql);
             }
             ////	END REMOVE
             ///////////////////////////////////////////////////////////////////////////
             ///////////////////////////////////////////////////////////////////////////
             ////	REBUILD INVITEE RELATIONSHIPS
             $focus->users_arr = array();
             $focus->users_arr = $userInvitees;
             $focus->contacts_arr = array();
             $focus->contacts_arr = $contactInvitees;
             $focus->leads_arr = array();
             $focus->leads_arr = $leadInvitees;
             if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
                 $focus->contacts_arr[] = $_POST['parent_id'];
             }
             if (!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') {
                 $focus->leads_arr[] = $_POST['parent_id'];
             }
             // Call the Call module's save function to handle saving other fields besides
             // the users and contacts relationships
             $focus->save(true);
             $return_id = $focus->id;
             // Process users
             $existing_users = array();
             if (!empty($_POST['existing_invitees'])) {
                 $existing_users = explode(",", trim($_POST['existing_invitees'], ','));
             }
             foreach ($focus->users_arr as $user_id) {
                 if (empty($user_id) || isset($existing_users[$user_id]) || isset($deleteUsers[$user_id])) {
                     continue;
                 }
                 if (!isset($acceptStatusUsers[$user_id])) {
                     $focus->load_relationship('users');
                     $focus->users->add($user_id);
                 } else {
                     // update query to preserve accept_status
                     $qU = 'UPDATE calls_users SET deleted = 0, accept_status = \'' . $acceptStatusUsers[$user_id] . '\' ';
                     $qU .= 'WHERE call_id = \'' . $focus->id . '\' ';
                     $qU .= 'AND user_id = \'' . $user_id . '\'';
                     $focus->db->query($qU);
                 }
             }
             // Process contacts
             $existing_contacts = array();
             if (!empty($_POST['existing_contact_invitees'])) {
                 $existing_contacts = explode(",", trim($_POST['existing_contact_invitees'], ','));
             }
             foreach ($focus->contacts_arr as $contact_id) {
                 if (empty($contact_id) || isset($existing_contacts[$contact_id]) || isset($deleteContacts[$contact_id]) && $contact_id != $_POST['parent_id']) {
                     continue;
                 }
                 if (!isset($acceptStatusContacts[$contact_id])) {
                     $focus->load_relationship('contacts');
                     $focus->contacts->add($contact_id);
                 } else {
                     // update query to preserve accept_status
                     $qU = 'UPDATE calls_contacts SET deleted = 0, accept_status = \'' . $acceptStatusContacts[$contact_id] . '\' ';
                     $qU .= 'WHERE call_id = \'' . $focus->id . '\' ';
                     $qU .= 'AND contact_id = \'' . $contact_id . '\'';
                     $focus->db->query($qU);
                 }
             }
             // Process leads
             $existing_leads = array();
             if (!empty($_POST['existing_lead_invitees'])) {
                 $existing_leads = explode(",", trim($_POST['existing_lead_invitees'], ','));
             }
             foreach ($focus->leads_arr as $lead_id) {
                 if (empty($lead_id) || isset($existing_leads[$lead_id]) || isset($deleteLeads[$lead_id]) && $lead_id != $_POST['parent_id']) {
                     continue;
                 }
                 if (!isset($acceptStatusLeads[$lead_id])) {
                     $focus->load_relationship('leads');
                     $focus->leads->add($lead_id);
                 } else {
                     // update query to preserve accept_status
                     $qU = 'UPDATE calls_leads SET deleted = 0, accept_status = \'' . $acceptStatusLeads[$lead_id] . '\' ';
                     $qU .= 'WHERE call_id = \'' . $focus->id . '\' ';
                     $qU .= 'AND lead_id = \'' . $lead_id . '\'';
                     $focus->db->query($qU);
                 }
             }
             // CCL - Comment out call to set $current_user as invitee
             //set organizer to auto-accept
             //$focus->set_accept_status($current_user, 'accept');
             ////	END REBUILD INVITEE RELATIONSHIPS
             ///////////////////////////////////////////////////////////////////////////
         }
     }
     if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Home') {
         $_REQUEST['return_action'] = 'index';
         handleRedirect('', 'Home');
     } else {
         if ($redirect) {
             handleRedirect($return_id, 'Calls');
         } else {
             return $focus;
         }
     }
 }
Exemple #26
0
 function handleSave($prefix, $redirect = true, $useRequired = false, $id = null)
 {
     global $current_user;
     $focus = new SavedSearch();
     if ($id) {
         $focus->retrieve($id);
     }
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $ignored_inputs = array('PHPSESSID', 'module', 'action', 'saved_search_name', 'saved_search_select', 'advanced', 'Calls_divs', 'ACLRoles_divs');
     $contents = $_REQUEST;
     if ($id == null) {
         $focus->name = $contents['saved_search_name'];
     }
     $focus->search_module = $contents['search_module'];
     foreach ($contents as $input => $value) {
         if (in_array($input, $ignored_inputs)) {
             unset($contents[$input]);
         }
     }
     $contents['advanced'] = true;
     $focus->contents = base64_encode(serialize($contents));
     $focus->assigned_user_id = $current_user->id;
     $focus->new_schema = true;
     $saved_search_id = $focus->save();
     $GLOBALS['log']->debug("Saved record with id of " . $focus->id);
     $orderBy = empty($contents['orderBy']) ? 'name' : $contents['orderBy'];
     $search_query = "&orderBy=" . $orderBy . "&sortOrder=" . $contents['sortOrder'] . "&query=" . $_REQUEST['query'] . "&searchFormTab=" . $_REQUEST['searchFormTab'] . '&showSSDIV=' . $contents['showSSDIV'];
     $this->handleRedirect($focus->search_module, $search_query, $saved_search_id, 'true');
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     $focus = new Account();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateAccounts = $this->checkForDuplicates($prefix);
         if (isset($duplicateAccounts)) {
             $location = 'module=Accounts&action=ShowDuplicates';
             $get = '';
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Accounts{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Accounts{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Accounts{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate account id's in redirect get string
             $i = 0;
             foreach ($duplicateAccounts as $account) {
                 $get .= "&duplicate[{$i}]=" . $account['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= '&return_module=';
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= 'Accounts';
             }
             $get .= '&return_action=';
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             //else $get .= 'DetailView';
             if (!empty($_POST['return_id'])) {
                 $get .= '&return_id=' . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             //now redirect the post to modules/Accounts/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $get));
             } else {
                 if (!empty($_POST['to_pdf'])) {
                     $location .= '&to_pdf=' . $_POST['to_pdf'];
                 }
                 $_SESSION['SHOW_DUPLICATES'] = $get;
                 header("Location: index.php?{$location}");
             }
             return null;
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Accounts';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&name=' . $focus->name;
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         handleRedirect($return_id, 'Accounts');
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/ClientOrders/Clientorder.php';
     require_once 'log4php/LoggerManager.php';
     require_once 'include/formbase.php';
     require_once 'include/TimeDate.php';
     require_once 'include/upload_file.php';
     require_once 'config.php';
     global $sugar_config;
     $timedate = new TimeDate();
     $focus = new Clientorder();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) {
         ACLController::displayNoAccess(true);
     }
     $upload_file = new UploadFile('uploadfile');
     if (isset($_FILES['uploadfile']) && $upload_file->confirm_upload()) {
         $focus->stored_file_name = $upload_file->get_stored_file_name();
         $focus->imagename = $upload_file->get_stored_file_name();
         $focus->imagepath = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name();
         $do_final_move = 1;
     }
     if (isset($_REQUEST['is_active']) && $_REQUEST['is_active'] == "1") {
         $focus->is_active = 1;
     } else {
         $focus->is_active = 0;
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     //Goodwill
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateClientOrders = $this->checkForDuplicates($prefix);
         if (isset($duplicateClientOrders)) {
             //$GLOBALS['log']->info("Duplicate Clientorder:".$duplicateClientOrders['id']);
             $this->handleRedirect($return_id, "ClientOrders");
             return null;
         }
     }
     //End Goodwill
     $return_id = $focus->save();
     if ($do_final_move) {
         $upload_file->final_move($return_id);
         $focus->stored_file_name = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name();
         $focus->imagename = $upload_file->get_stored_file_name();
         $focus->imagepath = $sugar_config['upload_dir'] . $return_id . $upload_file->get_stored_file_name();
         $focus->save();
         //echo "dir:".$sugar_config['upload_dir']."<br/>";
         //echo $focus->imagepath."<br/>";
     }
     //echo "Saved record with id of ".$return_id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if ($redirect) {
         handleRedirect($return_id, "ClientOrders");
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $theme, $current_user;
     $theme_path = "themes/" . $theme . "/";
     require_once 'modules/Ink/Ink.php';
     require_once $theme_path . 'layout_utils.php';
     require_once 'include/utils.php';
     require_once 'include/formbase.php';
     require_once 'XTemplate/xtpl.php';
     global $timedate;
     $focus = new Ink();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     } else {
         $focus = populateFromPost($prefix, $focus);
         // set dropdowns
         if (!isset($_POST[$prefix . 'active'])) {
             $focus->active = 'on';
         }
         if (!isset($_POST[$prefix . 'PMS_mix_charge'])) {
             $focus->PMS_mix_charge = 'off';
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     /*if($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect')
     	{
     		if (isset($_POST[$prefix.'sync_ink'])){
     			 $focus->inks_users_id = $current_user->id;
     		}
     		else{
     			if (!isset($focus->users))
     			{
     	      	  	$focus->load_relationship('user_sync');
     			}
     	      	$focus->inks_users_id = null;
     			$focus->user_sync->delete($focus->id, $current_user->id);
     		}
     	}*/
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     /*if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
     		$duplicateContacts = $this->checkForDuplicates($prefix);
     		if(isset($duplicateContacts)){
     			$get='module=Contacts&action=ShowDuplicates';
     			
     			if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
     				$get .= '&inbound_email_id='.$_POST['inbound_email_id'];
     			}
     			
     			//add all of the post fields to redirect get string
     			foreach ($focus->column_fields as $field) 
     			{
     				if (!empty($focus->$field))
     				{
     					$get .= "&Contacts$field=".urlencode($focus->$field);
     				}	
     			}
     			
     			foreach ($focus->additional_column_fields as $field) 
     			{
     				if (!empty($focus->$field))
     				{
     					$get .= "&Contacts$field=".urlencode($focus->$field);
     				}	
     			}
     
     			//create list of suspected duplicate ink id's in redirect get string
     			$i=0;
     			foreach ($duplicateContacts as $ink)
     			{
     				$get .= "&duplicate[$i]=".$ink['id'];
     				$i++;
     			}
     
     			//add return_module, return_action, and return_id to redirect get string
     			$get .= "&return_module=";
     			if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
     			else $get .= "Contacts";
     			$get .= "&return_action=";
     			if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
     			else $get .= "DetailView";
     			if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
     			if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
     			if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
     			
     			// for InboundEmail flow
     			if(!empty($_POST['start'])) $get .= '&start='.$_POST['start'];
     			//now redirect the post to modules/Contacts/ShowDuplicates.php
                 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
                 {
                     $json = getJSONobj();
                     echo $json->encode(array('status' => 'dupe', 
                                              'get' => $get));           
                 }
                 else {
                     if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
                     header("Location: index.php?$get");
                 }
     			return null;
     		}
     	}*/
     global $current_user;
     /*if(is_admin($current_user)){
     		if (!isset($_POST[$prefix.'portal_active'])) $focus->portal_active = '0';
     		//if no password is set set account to inactive for portal
     		if(empty($_POST[$prefix.'portal_name']))$focus->portal_active = '0';
     		
     	}*/
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         return null;
     }
     if (isset($_POST['return_side']) && !empty($_POST['return_side'])) {
         $_REQUEST['custom_var'] = $_POST['return_side'];
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $_REQUEST['mode'] = "MULTISELECT";
         return;
     }
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/Supplies/Supply.php';
     require_once 'modules/SupplyLines/SupplyLine.php';
     require_once 'log4php/LoggerManager.php';
     require_once 'include/formbase.php';
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $focus = new Supply();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) {
         ACLController::displayNoAccess(true);
     }
     $return_id = $focus->save();
     $supplyLine1 = new SupplyLine();
     $supplyLine1->mark_deletedBySupplyid($return_id);
     $count = count($_POST);
     $keys = array_keys($_POST);
     $sum = 0;
     for ($i = 0; $i < $count; $i++) {
         //echo $keys[$i]."<br>";
         if (substr_count($keys[$i], "materialname_") > 0) {
             $index = substr($keys[$i], strpos($keys[$i], "_") + 1);
             $materialid = $_POST["materialid_" . $index];
             $paperid = $_POST["paperid_" . $index];
             if (!isset($materialid) && empty($materialid) && !isset($paperid) && empty($paperid)) {
                 continue;
             }
             $materialname = $_POST["materialname_" . $index];
             $number = $_POST["number_" . $index];
             $measure = $_POST["measure_" . $index];
             $unit = $_POST["unit_" . $index];
             $singlep = $_POST["singlep_" . $index];
             $price = $_POST["price_" . $index];
             $supplynum = $_POST["supplynum"];
             $status = $_POST["status"];
             $delivery_date = $_POST["delivery_date"];
             $delivered_date = $_POST["delivered_date"];
             $supplyLine = new SupplyLine();
             $supplyLine->number = $number;
             $supplyLine->materialid = $materialid;
             $supplyLine->paperid = $paperid;
             $supplyLine->materialname = $materialname;
             $supplyLine->measure = $measure;
             $supplyLine->unit = $unit;
             $supplyLine->singlep = $singlep;
             $supplyLine->price = $price;
             $supplyLine->supplynum = $supplynum;
             $supplyLine->supplyid = $return_id;
             $supplyLine->status = $status;
             $supplyLine->delivery_date = $delivery_date;
             $supplyLine->delivered_date = $delivered_date;
             $supplyLine->save();
         }
     }
     $count = $_POST["product_count"];
     //	$GLOBLES['log']->debug("Saved record with id of ".$return_id);
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }