예제 #1
0
 /**
  * function to save the imported organization
  * @param object $import_object
  * @param object $do_crm_fields
  * @param array $data
  * @return integer inseted recordid
  */
 public function import_save($import_object, $crm_fields, $data)
 {
     $mapped_fields = $import_object->get_mapped_fields();
     $table_entity = 'organization';
     $table_entity_address = 'organization_address';
     $table_entity_custom = 'organization_custom_fld';
     $entity_data_array = array();
     $custom_data_array = array();
     $addr_data_array = array();
     foreach ($crm_fields as $crm_fields) {
         $field_name = $crm_fields["field_name"];
         $mapped_field_key = array_search($field_name, $mapped_fields);
         if ($mapped_field_key !== false) {
             $field_value = $data[$mapped_field_key];
             $field_value = $import_object->format_data_before_save($crm_fields["field_type"], $field_value);
         } else {
             $field_value = '';
         }
         if ($field_name == 'assigned_to') {
             $field_name = 'iduser';
             $field_value = $_SESSION["do_user"]->iduser;
         }
         if ($field_name == 'member_of') {
             $field_value = $this->map_member_of($field_value);
         }
         if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) {
             $entity_data_array[$field_name] = $field_value;
         }
         if ($crm_fields["table_name"] == $table_entity_address && $crm_fields["idblock"] > 0) {
             $addr_data_array[$field_name] = $field_value;
         }
         if ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) {
             $custom_data_array[$field_name] = $field_value;
         }
     }
     $this->insert($table_entity, $entity_data_array);
     $id_entity = $this->getInsertId();
     if ($id_entity > 0) {
         //adding the added_on
         $q_upd = "\n\t\t\tupdate `" . $this->getTable() . "` \n\t\t\tset `added_on` = ? \n\t\t\twhere `" . $this->primary_key . "` = ?";
         $this->query($q_upd, array(date("Y-m-d H:i:s"), $id_entity));
         $custom_data_array["idorganization"] = $id_entity;
         $addr_data_array["idorganization"] = $id_entity;
         $this->insert($table_entity_custom, $custom_data_array);
         $this->insert($table_entity_address, $addr_data_array);
         $do_data_history = new DataHistory();
         $do_data_history->add_history($id_entity, 6, 'add');
         $do_data_history->free();
         return $id_entity;
     } else {
         return false;
     }
 }
예제 #2
0
 /**
  * Event function to update the organization data
  * @param object $evctl
  */
 public function eventEditRecord(EventControler $evctl)
 {
     $id_entity = (int) $evctl->sqrecord;
     if ($id_entity > 0 && true === $_SESSION["do_crm_action_permission"]->action_permitted('edit', 11, (int) $evctl->sqrecord)) {
         $obj = $this->getId($id_entity);
         $obj = (object) $obj;
         // convert the data array to Object
         $do_process_plugins = new CRMPluginProcessor();
         // process before update plugin. If any error is raised display that.
         $do_process_plugins->process_action_plugins((int) $evctl->idmodule, $evctl, 3, $id_entity, $obj);
         if (strlen($do_process_plugins->get_error()) > 2) {
             $_SESSION["do_crm_messages"]->set_message('error', $do_process_plugins->get_error());
             $next_page = NavigationControl::getNavigationLink($evctl->module, "edit");
             $dis = new Display($next_page);
             $dis->addParam("sqrecord", $id_entity);
             if ($evctl->return_page != '') {
                 $dis->addParam("return_page", $evctl->return_page);
             }
             $evctl->setDisplayNext($dis);
         } else {
             $do_crm_fields = new CRMFields();
             $crm_fields = $do_crm_fields->get_field_information_by_module_as_array((int) $evctl->idmodule);
             $table_entity = 'vendor';
             $table_entity_address = 'vendor_address';
             $table_entity_custom = 'vendor_custom_fld';
             $table_entity_to_grp = 'vendor_to_grp_rel';
             $entity_data_array = array();
             $custom_data_array = array();
             $addr_data_array = array();
             $assigned_to_as_group = false;
             foreach ($crm_fields as $crm_fields) {
                 $field_name = $crm_fields["field_name"];
                 $field_value = $do_crm_fields->convert_field_value_onsave($crm_fields, $evctl, 'edit');
                 if (is_array($field_value) && count($field_value) > 0) {
                     if ($field_value["field_type"] == 15) {
                         $field_name = 'iduser';
                         $value = $field_value["value"];
                         $assigned_to_as_group = $field_value["assigned_to_as_group"];
                         $group_id = $field_value["group_id"];
                     } elseif ($field_value["field_type"] == 12) {
                         $value = $field_value["name"];
                         $avatar_array[] = $field_value;
                     }
                 } else {
                     $value = $field_value;
                 }
                 if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) {
                     $entity_data_array[$field_name] = $value;
                 }
                 if ($crm_fields["table_name"] == $table_entity_address && $crm_fields["idblock"] > 0) {
                     $addr_data_array[$field_name] = $value;
                 }
                 if ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) {
                     $custom_data_array[$field_name] = $value;
                 }
             }
             $this->update(array($this->primary_key => $id_entity), $table_entity, $entity_data_array);
             //updating the last_modified,last_modified_by
             $q_upd = "\n\t\t\t\tupdate `" . $this->getTable() . "` set \n\t\t\t\t`last_modified` = ? ,\n\t\t\t\t`last_modified_by` = ? \n\t\t\t\twhere `" . $this->primary_key . "` = ?";
             $this->query($q_upd, array(date("Y-m-d H:i:s"), $_SESSION["do_user"]->iduser, $id_entity));
             if (count($custom_data_array) > 0) {
                 $this->update(array($this->primary_key => $id_entity), $table_entity_custom, $custom_data_array);
             }
             if (count($addr_data_array) > 0) {
                 $this->update(array($this->primary_key => $id_entity), $table_entity_address, $addr_data_array);
             }
             if ($assigned_to_as_group === false) {
                 $qry_grp_rel = "DELETE from `{$table_entity_to_grp}` where idvendor = ? LIMIT 1";
                 $this->query($qry_grp_rel, array($id_entity));
             } else {
                 $qry_grp_rel = "select * from `{$table_entity_to_grp}` where idvendor = ?";
                 $this->query($qry_grp_rel, array($id_entity));
                 if ($this->getNumRows() > 0) {
                     $this->next();
                     $id_grp_rel = $this->idvendor_to_grp_rel;
                     $q_upd = "\n\t\t\t\t\t\tupdate `{$table_entity_to_grp}` set \n\t\t\t\t\t\t`idgroup` = ?\n\t\t\t\t\t\twhere `idvendor_to_grp_rel` = ? LIMIT 1";
                     $this->query($q_upd, array($group_id, $id_grp_rel));
                 } else {
                     $this->insert($table_entity_to_grp, array("idvendor" => $id_entity, "idgroup" => $group_id));
                 }
             }
             // Record the history
             $do_data_history = new DataHistory();
             $do_data_history->add_history($id_entity, (int) $evctl->idmodule, 'edit');
             $do_data_history->add_history_value_changes($id_entity, (int) $evctl->idmodule, $obj, $evctl);
             //record the feed
             $feed_other_assigne = array();
             if ($assigned_to_as_group === true) {
                 $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => $group_id));
             }
             $do_feed_queue = new LiveFeedQueue();
             $do_feed_queue->add_feed_queue($id_entity, (int) $evctl->idmodule, $evctl->vendor_name, 'edit', $feed_other_assigne);
             // process after update plugin
             $do_process_plugins->process_action_plugins((int) $evctl->idmodule, $evctl, 4, $id_entity, $obj);
             $_SESSION["do_crm_messages"]->set_message('success', _('Data updated successfully !'));
             $next_page = NavigationControl::getNavigationLink($evctl->module, "detail");
             $dis = new Display($next_page);
             $dis->addParam("sqrecord", $id_entity);
             $evctl->setDisplayNext($dis);
         }
     } else {
         $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to edit the record ! '));
         $next_page = NavigationControl::getNavigationLink($evctl->module, "list");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     }
 }
예제 #3
0
 /**
  * function to map related to (contacts) for potentials while importing
  * checks if the contact exists else adds a new contact
  * @param string $contact_name
  * @return integer idcontacts
  */
 public function map_related_to_contacts($contact_name)
 {
     if (strlen($contact_name) > 2) {
         $contact_name = trim($contact_name);
         $do_contact = new Contacts();
         $qry = "\n\t\t\tselect `idcontacts`\n\t\t\tfrom  `contacts`\n\t\t\twhere `deleted` = 0 \n\t\t\tAND iduser = "******"do_user"]->iduser . "\n\t\t\tAND \n\t\t\t(\n\t\t\t\tconcat(firstname,' ',lastname) = ?\n\t\t\t\tor\n\t\t\t\tconcat(lastname,' ',firstname) = ?\n\t\t\t)\n\t\t\t";
         $do_contact->query($qry, array($contact_name, $contact_name));
         if ($do_contact->getNumRows() > 0) {
             $do_contact->next();
             return $do_contact->idcontacts;
         } else {
             $contact_name_explode = explode(" ", $contact_name);
             $do_contact->insert("contacts", array("firstname" => CommonUtils::purify_input($contact_name_explode[0]), "lastname" => CommonUtils::purify_input($contact_name_explode[1]), "iduser" => $_SESSION["do_user"]->iduser));
             $idcontacts = $do_contact->getInsertId();
             //adding the added_on
             $q_upd = "\n\t\t\t\tupdate `contacts` \n\t\t\t\tset `added_on` = '" . date("Y-m-d H:i:s") . "'\n\t\t\t\twhere `idcontacts` = " . $idcontacts;
             $do_contact->query($q_upd);
             $do_contact->insert("contacts_custom_fld", array("idcontacts" => $idcontacts));
             $do_contact->insert("contacts_address", array("idcontacts" => $idcontacts));
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idcontacts, 4, 'add');
             $do_data_history->free();
             return $idcontacts;
         }
     }
 }
예제 #4
0
파일: User.class.php 프로젝트: sQcrm/sqcrm
 /**
  * Event Function to update user information
  * @param object $evctl
  */
 public function eventEditRecord(EventControler $evctl)
 {
     $permission = $_SESSION["do_user"]->is_admin == 1 ? true : false;
     $iduser = (int) $evctl->sqrecord;
     if ($iduser > 0 && true === $permission) {
         $this->getId($iduser);
         $do_crm_fields = new CRMFields();
         $crm_fields = $do_crm_fields->get_field_information_by_module_as_array((int) $evctl->idmodule);
         $data_array = array();
         foreach ($crm_fields as $crm_fields) {
             if ($crm_fields["field_type"] == 11) {
                 continue;
             }
             $field_name = $crm_fields["field_name"];
             $field_value = $do_crm_fields->convert_field_value_onsave($crm_fields, $evctl, 'edit');
             if (is_array($field_value) && count($field_value) > 0) {
                 if ($field_value["field_type"] == 12) {
                     $value = $field_value["name"];
                     $avatar_array[] = $field_value;
                 }
             } else {
                 $value = $field_value;
             }
             $data_array[$field_name] = $value;
         }
         $this->update(array($this->primary_key => $iduser), $this->getTable(), $data_array);
         if (is_array($avatar_array) && count($avatar_array) > 0) {
             foreach ($avatar_array as $avatar) {
                 if (is_array($avatar) && array_key_exists('name', $avatar)) {
                     $do_files_and_attachment = new CRMFilesAndAttachments();
                     $do_files_and_attachment->addNew();
                     $do_files_and_attachment->file_name = $avatar["name"];
                     $do_files_and_attachment->file_mime = $avatar["mime"];
                     $do_files_and_attachment->file_size = $avatar["file_size"];
                     $do_files_and_attachment->file_extension = $avatar["extension"];
                     $do_files_and_attachment->idmodule = 7;
                     $do_files_and_attachment->id_referrer = $iduser;
                     $do_files_and_attachment->iduser = 1;
                     $do_files_and_attachment->date_modified = date("Y-m-d H:i:s");
                     $do_files_and_attachment->add();
                 }
             }
         }
         // Record the history
         $do_data_history = new DataHistory();
         $do_data_history->add_history($iduser, 7, 'edit');
         $do_data_history->add_history_value_changes($iduser, 7, $this, $evctl);
         $_SESSION["do_crm_messages"]->set_message('success', _('Data updated successfully !'));
     } else {
         $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to add record !'));
         $next_page = NavigationControl::getNavigationLink("User", "list");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     }
 }
예제 #5
0
 public function map_products_vendor($vendor_name)
 {
     $security_where = $_SESSION["do_crm_action_permission"]->get_user_where_condition('vendor', 11);
     $qry = "select * from `vendor` where `vendor_name` = ? " . $security_where;
     $stmt = $this->getDbConnection()->executeQuery($qry, array($vendor_name));
     if ($stmt->rowCount() > 0) {
         $data = $stmt->fetch();
         $idvendor = $data["idvendor"];
         return $idvendor;
     } else {
         if (strlen($vendor_name) > 0) {
             $do_vendor = new Vendor();
             $data = array("vendor_name" => CommonUtils::purify_input($vendor_name), "iduser" => $_SESSION["do_user"]->iduser, "added_on" => date("Y-m-d H:i:s"));
             $do_vendor->insert("vendor", $data);
             $idvendor = $do_vendor->getInsertId();
             $do_vendor->insert("vendor_address", array("idvendor" => $idvendor));
             $do_vendor->insert("vendor_custom_fld", array("idvendor" => $idvendor));
             $do_vendor->free();
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idvendor, 11, 'add');
             $do_data_history->free();
             return $idvendor;
         }
     }
 }
예제 #6
0
 /**
  * Constructor function 
  */
 function __construct(sqlConnect $conx = NULL, $table_name = "")
 {
     parent::__construct($conx, $table_name);
 }
예제 #7
0
 /**
  * event function to change the assigned to for entity for a module
  * The method will check the assigned to value, if its group or user
  * and then accordingly will change the assigned to
  * @param object $evctl
  */
 function eventChangeAssignedToEntity(EventControler $evctl)
 {
     $next_page = $evctl->next_page;
     $record_ids = $evctl->ids;
     $group_transfer_opt = false;
     $transfer_to_user = false;
     $transfer_to_group = false;
     $module_name = $evctl->module;
     $module_id = $evctl->module_id;
     if ($evctl->group_transfer_opt == 'yes') {
         $group_transfer_opt = true;
     }
     if ($group_transfer_opt === true) {
         if ($evctl->assigned_to_selector == 'user') {
             $transfer_to_user = true;
         } elseif ($evctl->assigned_to_selector == 'group') {
             $transfer_to_group = true;
         }
     } else {
         $transfer_to_user = true;
     }
     if (($transfer_to_user === true || $transfer_to_group === true) && sizeof($record_ids) > 0) {
         $do_data_history = new DataHistory();
         $do_feed_queue = new LiveFeedQueue();
         $module = new $module_name();
         if ($transfer_to_user === true) {
             $do_user = new User();
             $do_user->getId((int) $evctl->user_selector);
             $new_assigned_to = $do_user->user_name;
             foreach ($record_ids as $id) {
                 $feed_other_assigne = array();
                 $module->getId($id);
                 $old_assigned_to = $module->assigned_to;
                 if ($module->idgroup > 0) {
                     $feed_other_assigne = array("related" => "group", "data" => array("key" => "oldgroup", "val" => $module->idgroup));
                 }
                 $record_identifier = $this->get_entity_identifier('', '', $module);
                 // query to change the user for the record
                 $qry = "\n\t\t\t\t\tupdate `" . $module->getTable() . "` \n\t\t\t\t\tset `iduser` = ?\n\t\t\t\t\twhere `" . $module->primary_key . "` = ?";
                 $this->query($qry, array($evctl->user_selector, $id));
                 //qry to delete from the group rel if data exists
                 $qry = "\n\t\t\t\t\tdelete from `" . $module->module_group_rel_table . "` \n\t\t\t\t\twhere \n\t\t\t\t\t`" . $module->primary_key . "` = ?";
                 $this->query($qry, array($id));
                 // add to data history
                 $do_data_history->addNew();
                 $do_data_history->id_referrer = $id;
                 $do_data_history->iduser = $_SESSION["do_user"]->iduser;
                 $do_data_history->idmodule = $module_id;
                 $do_data_history->date_modified = date("Y-m-d H:i:s");
                 $do_data_history->action = 'value_changes';
                 $do_data_history->idfields = (int) $evctl->fieldid;
                 $do_data_history->old_value = $old_assigned_to;
                 $do_data_history->new_value = $new_assigned_to;
                 $do_data_history->add();
                 // add to feed
                 $do_feed_queue->add_feed_queue($id, $module_id, $record_identifier, 'changed_assigned_to', $feed_other_assigne);
             }
         } elseif ($transfer_to_group === true) {
             $do_group = new Group();
             $do_group->getId((int) $evctl->group_selector);
             $new_assigned_to = $do_group->group_name;
             foreach ($record_ids as $id) {
                 $module->getId($id);
                 $old_assigned_to = $module->assigned_to;
                 if ($module->idgroup > 0) {
                     $feed_other_assigne = array("related" => "group", "data" => array("key" => "oldgroup", "val" => $module->idgroup));
                 }
                 $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => (int) $evctl->group_selector));
                 $record_identifier = $this->get_entity_identifier('', '', $module);
                 // query to change the iduser to 0 for the record
                 $qry = "\n\t\t\t\t\tupdate `" . $module->getTable() . "` \n\t\t\t\t\tset `iduser` = 0 \n\t\t\t\t\twhere `" . $module->primary_key . "` = ?";
                 $this->query($qry, array($id));
                 // now check if the record is already assigned to a different group then update else add a new entry
                 $qry_check = "\n\t\t\t\t\tselect * from `" . $module->module_group_rel_table . "` \n\t\t\t\t\twhere \n\t\t\t\t\t`" . $module->primary_key . "` = ?";
                 $this->query($qry_check, array($id));
                 if ($this->getNumRows() > 0) {
                     $qry = "\n\t\t\t\t\t\tupdate `" . $module->module_group_rel_table . "` \n\t\t\t\t\t\tset `idgroup` = ?\n\t\t\t\t\t\twhere `" . $module->primary_key . "` = ?";
                     $this->query($qry, array($evctl->group_selector, $id));
                 } else {
                     $this->insert($module->module_group_rel_table, array($module->primary_key => $id, 'idgroup' => $evctl->group_selector));
                 }
                 // add to data history
                 $do_data_history->addNew();
                 $do_data_history->id_referrer = $id;
                 $do_data_history->iduser = $_SESSION["do_user"]->iduser;
                 $do_data_history->idmodule = $module_id;
                 $do_data_history->date_modified = date("Y-m-d H:i:s");
                 $do_data_history->action = 'value_changes';
                 $do_data_history->idfields = (int) $evctl->fieldid;
                 $do_data_history->old_value = $old_assigned_to;
                 $do_data_history->new_value = $new_assigned_to;
                 $do_data_history->add();
                 // add to feed
                 $do_feed_queue->add_feed_queue($id, $module_id, $record_identifier, 'changed_assigned_to', $feed_other_assigne);
             }
         }
         $_SESSION["do_crm_messages"]->set_message('success', _('Data updated successfully !'));
     }
 }
예제 #8
0
 /**
  * Event function to convert lead
  * The conversion process goes as -
  * if a new organization is set to be created then create it and transfer other information and mapped custom fields.
  * if a new contact is set to be created then create it and transfer other information and mapped custom fields.
  * if a new potential is set to be created then create it and transfer other information and mapped custom fields,also
  * see the related to and if organization is created or selected then the related to is set to idorganization, else related
  * to should be idcontacts depending on if its created or selected from the conversion form.
  * if no potential is set to be created then check what is set to be created, and if just organization or contact is set to 
  * be created then create and transfer the data and custom fields mapped information.
  * if both organization and contact is set to be created then the created contact is mapped to the organization which is created
  * or selected.
  * if both organization and contact or one of them is set to be conveted and instead of creating if the values are selected
  * then nothing to be done.
  * @param object $evctl
  * @see popups/convert_lead_modal.php
  */
 public function eventConvertLeads(EventControler $evctl)
 {
     $idleads = (int) $evctl->idleads;
     $idcontacts = 0;
     $idorganization = 0;
     $idpotentials = 0;
     $create_potential = false;
     $create_organization = false;
     $create_contact = false;
     $assigned_to_as_group = false;
     $group_id = 0;
     $assigned_to = $evctl->assigned_to_selector;
     if ($assigned_to == 'user') {
         $fld_value = $evctl->user_selector;
     } else {
         $fld_value = 0;
         $group_id = $evctl->group_selector;
         $assigned_to_as_group = true;
     }
     $assigned_to_data = array("value" => $fld_value, "assigned_to_as_group" => $assigned_to_as_group, "group_id" => $group_id);
     if ($evctl->pot_convertion == 'on' && true === $_SESSION["do_crm_action_permission"]->action_permitted('add', 5)) {
         $create_potential = true;
     }
     if ($evctl->org_convertion == 'on' && true === $_SESSION["do_crm_action_permission"]->action_permitted('add', 6)) {
         $create_organization = true;
     }
     if ($evctl->cnt_convertion == 'on' && true === $_SESSION["do_crm_action_permission"]->action_permitted('add', 4)) {
         $create_contact = true;
     }
     $do_convert = true;
     if ($create_organization === true && $evctl->select_org == 'on' && $create_potential === false && $create_contact === false) {
         $do_convert = false;
     }
     if ($create_contact === true && $evctl->select_cnt == 'on' && $create_potential === false && $create_organization === false) {
         $do_convert = false;
     }
     if ($do_convert === true) {
         $this->getId($idleads);
         $do_feed_queue = new LiveFeedQueue();
         $do_data_history = new DataHistory();
         $related_identifier_data = array("related_identifier" => $this->firstname . ' ' . $this->lastname, "related_identifier_idrecord" => $idleads, "related_identifier_idmodule" => 3);
         //add to feed queue
         $feed_other_assigne = array();
         if ($this->idgroup > 0) {
             $feed_other_assigne = array("related" => "group", "data" => array("key" => "oldgroup", "val" => $this->idgroup));
         }
         $do_feed_queue->add_feed_queue($idleads, 3, $this->firstname . ' ' . $this->lastname, 'lead_covert', $feed_other_assigne);
         // add to data history
         $do_data_history->add_history($idleads, 3, 'add');
         $do_fields_mapping = new CRMFieldsMapping();
         $qry_mapped_fields = "\n\t\t\tselect custom_field_mapping.*,\n\t\t\tfields.field_name as lead_field_name\n\t\t\tfrom custom_field_mapping\n\t\t\tinner join fields on fields.idfields = custom_field_mapping.mapping_field_id";
         $stmt = $do_fields_mapping->getDbConnection()->executeQuery($qry_mapped_fields);
         $mapped_fields = $stmt->fetchAll();
         $do_custom_field_map = false;
         if (count($mapped_fields) > 0) {
             $do_custom_field_map = true;
         }
         if ($create_organization === true) {
             if ($evctl->create_org == 'on') {
                 $idorganization = $this->create_new_organization_converted($evctl, $assigned_to_data);
                 // add to feed queue
                 $feed_other_assigne = array();
                 if ($assigned_to_as_group === true) {
                     $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => $group_id));
                 }
                 $do_feed_queue->add_feed_queue($idorganization, 6, $evctl->organization_name, 'add_organization_lead_convert', $feed_other_assigne, $related_identifier_data);
                 // add to data history
                 $do_data_history->add_history($idorganization, 6, 'add');
                 $map_entity = "\n\t\t\t\t\tUPDATE \n\t\t\t\t\t`organization`\n\t\t\t\t\tset \n\t\t\t\t\t`rating` = ?,\n\t\t\t\t\t`phone` = ?,\n\t\t\t\t\t`fax` = ? \n\t\t\t\t\twhere `idorganization` = ? limit 1 ";
                 $this->getDbConnection()->executeQuery($map_entity, array($this->rating, $this->phone, $this->fax, $idorganization));
                 $map_addr = "\n\t\t\t\t\tUPDATE \n\t\t\t\t\t`organization_address` \n\t\t\t\t\tset\n\t\t\t\t\t`org_bill_address` = ?,\n\t\t\t\t\t`org_bill_pobox` = ?,\n\t\t\t\t\t`org_bill_city` = ?,\n\t\t\t\t\t`org_bill_state` = ?,\n\t\t\t\t\t`org_bill_postalcode` = ?,\n\t\t\t\t\t`org_bill_country` = ?\n\t\t\t\t\twhere `idorganization` = ? limit 1 ";
                 $this->getDbConnection()->executeQuery($map_addr, array($this->street, $this->po_box, $this->city, $this->state, $this->postal_code, $this->country, $idorganization));
                 if ($do_custom_field_map === true) {
                     $this->update_mapped_fields_data(6, $idorganization, $mapped_fields);
                 }
             } elseif ($evctl->select_org == 'on') {
                 $idorganization = $evctl->idorganization;
             }
         }
         if ($create_contact === true) {
             if ($evctl->create_cnt == 'on') {
                 $idcontacts = $this->create_new_contact_converted($evctl, $assigned_to_data, $idorganization);
                 // add to feed queue
                 $feed_other_assigne = array();
                 if ($assigned_to_as_group === true) {
                     $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => $group_id));
                 }
                 $do_feed_queue->add_feed_queue($idcontacts, 4, $evctl->firstname . ' ' . $evctl->lastname, 'add_contact_lead_convert', $feed_other_assigne, $related_identifier_data);
                 // add to data history
                 $do_data_history->add_history($idcontacts, 4, 'add');
                 $map_entity = "\n\t\t\t\t\tUPDATE\n\t\t\t\t\t`contacts`\n\t\t\t\t\tset \n\t\t\t\t\t`office_phone` = ?,\n\t\t\t\t\t`mobile_num` = ?,\n\t\t\t\t\t`leadsource` = ?,\n\t\t\t\t\t`title` = ?,\n\t\t\t\t\t`fax` = ?\n\t\t\t\t\twhere `idcontacts` = ? limit 1 ";
                 $this->getDbConnection()->executeQuery($map_entity, array($this->phone, $this->mobile, $this->leadsource, $this->title, $this->fax, $idcontacts));
                 $map_addr = "\n\t\t\t\t\tUPDATE\n\t\t\t\t\t`contacts_address`\n\t\t\t\t\tset\n\t\t\t\t\t`cnt_mail_street` = ?,\n\t\t\t\t\t`cnt_mail_pobox` = ?,\n\t\t\t\t\t`cnt_mailing_city` = ?,\n\t\t\t\t\t`cnt_mailing_state` = ?,\n\t\t\t\t\t`cnt_mailing_postalcode` = ?,\n\t\t\t\t\t`cnt_mailing_country` = ?\n\t\t\t\t\twhere `idcontacts` = ? limit 1 ";
                 $this->getDbConnection()->executeQuery($map_addr, array($this->street, $this->po_box, $this->city, $this->state, $this->postal_code, $this->country, $idcontacts));
                 if ($do_custom_field_map === true) {
                     $this->update_mapped_fields_data(4, $idcontacts, $mapped_fields);
                 }
             } elseif ($evctl->select_cnt == 'on') {
                 $idcontacts = $evctl->idcontacts;
             }
         }
         if ($create_potential === true) {
             if ($idorganization > 0 && $create_organization === true) {
                 $related_to = $idorganization;
                 $related_to_module = 6;
             } elseif ($idcontacts > 0 && $create_contact === true) {
                 $related_to = $idcontacts;
                 $related_to_module = 4;
             } else {
                 $related_to = $idorganization;
                 $related_to_module = 6;
             }
             $idpotentials = $this->create_new_potential_converted($evctl, $assigned_to_data, $related_to, $related_to_module);
             if ($do_custom_field_map === true) {
                 $this->update_mapped_fields_data(5, $idpotentials, $mapped_fields);
             }
             // add to feed queue
             $feed_other_assigne = array();
             if ($assigned_to_as_group === true) {
                 $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => $group_id));
             }
             $do_feed_queue->add_feed_queue($idpotentials, 5, $evctl->potential_name, 'add_potential_lead_convert', $feed_other_assigne, $related_identifier_data);
             // add to data history
             $do_data_history->add_history($idpotentials, 5, 'add');
         }
         if ($idpotentials > 0) {
             $next_page = NavigationControl::getNavigationLink("Potentials", "detail");
             $sqrecord = $idpotentials;
         } elseif ($idorganization > 0 && $evctl->create_org == 'on') {
             $next_page = NavigationControl::getNavigationLink("Organization", "detail");
             $sqrecord = $idorganization;
         } else {
             $next_page = NavigationControl::getNavigationLink("Contacts", "detail");
             $sqrecord = $idcontacts;
         }
         $this->query("update " . $this->getTable() . " set `converted` = 1 where idleads = ? limit 1", array($idleads));
         if ($evctl->create_org == 'on') {
             $idorganization_converted = $idorganization;
         } else {
             $idorganization_converted = 0;
         }
         if ($evctl->create_cnt == 'on') {
             $idcontacts_converted = $idcontacts;
         } else {
             $idcontacts_converted = 0;
         }
         $this->record_lead_conversion_matrix($idleads, $idpotentials, $idorganization_converted, $idcontacts_converted);
         // transfer the related data to the selected one
         if ((int) $evctl->transfer_related_data == 1) {
             $transfer_module_id = 6;
             $idtransfer_to = $idorganization;
         } elseif ((int) $evctl->transfer_related_data == 2) {
             $transfer_module_id = 4;
             $idtransfer_to = $idcontacts;
         } elseif ((int) $evctl->transfer_related_data == 3) {
             $transfer_module_id = 5;
             $idtransfer_to = $idpotentials;
         }
         $this->transfer_relateddata_on_conversion($idleads, $idtransfer_to, $transfer_module_id);
         $dis = new Display($next_page);
         $dis->addParam("sqrecord", $sqrecord);
         $evctl->setDisplayNext($dis);
     } else {
         $_SESSION["do_crm_messages"]->set_message('error', _('No conversion has been done, please try again !'));
     }
 }
예제 #9
0
 /**
  * event function to mass update the Calendar events and set their status 
  * @param object $evctl
  * @return void
  */
 public function eventChangeEventStatus(EventControler $evctl)
 {
     $record_ids = $evctl->ids;
     $event_status = $evctl->event_status;
     if (count($record_ids) > 0) {
         $do_data_history = new DataHistory();
         $do_feed_queue = new LiveFeedQueue();
         $idfields = 0;
         $qry = "\n\t\t\tselect idfields from fields\n\t\t\twhere field_name = 'event_status'\n\t\t\tand table_name = 'events'\n\t\t\t";
         $stmt = $this->getDbConnection()->executeQuery($qry);
         $data = $stmt->fetch();
         $idfields = $data['idfields'];
         foreach ($record_ids as $id) {
             $this->getId($id);
             $record_identifier = $this->subject;
             $old_status = $this->event_status;
             $assigned_to_as_group = false;
             $group_id = 0;
             if ((int) $this->idgroup > 0) {
                 $assigned_to_as_group = true;
                 $group_id = (int) $this->idgroup;
             }
             $qry = "update `" . $this->getTable() . "`\n\t\t\t\tset `event_status` = ?\n\t\t\t\twhere `idevents` = ?\n\t\t\t\t";
             $stmt = $this->getDbConnection()->executeQuery($qry, array($event_status, $id));
             if ($old_status != $event_status) {
                 $do_data_history->addNew();
                 $do_data_history->id_referrer = $id;
                 $do_data_history->iduser = $_SESSION["do_user"]->iduser;
                 $do_data_history->idmodule = 2;
                 $do_data_history->date_modified = date("Y-m-d H:i:s");
                 $do_data_history->action = 'value_changes';
                 $do_data_history->idfields = $idfields;
                 $do_data_history->old_value = $old_status;
                 $do_data_history->new_value = $event_status;
                 $do_data_history->add();
                 // add to feed
                 $feed_other_assigne = array();
                 if ($assigned_to_as_group === true) {
                     $feed_other_assigne = array("related" => "group", "data" => array("key" => "oldgroup", "val" => $group_id));
                 }
                 $do_feed_queue->add_feed_queue($id, 2, $record_identifier, 'edit', $feed_other_assigne);
             }
         }
         $_SESSION["do_crm_messages"]->set_message('success', _('Events updated successfully !'));
     } else {
         $_SESSION["do_crm_messages"]->set_message('success', _('Missing record id(s) !'));
     }
 }
예제 #10
0
 /**
  * function to delete single record from list view and related list view
  * @param object $evctl
  * @return 0 or 1
  * @see view/listview.php
  * @see view/related_listview_entry.php
  */
 function eventAjaxDeleteSingleEntity(EventControler $evctl)
 {
     $referrer = $evctl->referrer;
     if ($referrer == 'list') {
         $module = $evctl->module;
     } elseif ($referrer == 'related') {
         $idrelated_information = (int) $evctl->related_record_id;
         $do_related_information = new CRMRelatedInformation();
         $do_related_information->getId($idrelated_information);
         if ($do_related_information->getNumRows() > 0) {
             $module = $do_related_information->related_module;
         }
     }
     if ($module != '') {
         $module_id = $_SESSION["do_module"]->get_idmodule_by_name($module, $_SESSION["do_module"]);
         $id = (int) $evctl->sqrecord;
         $allow_del = $_SESSION["do_crm_action_permission"]->action_permitted('delete', $module_id, $id);
         if ($allow_del === true) {
             $do_data_history = new DataHistory();
             $crm_entity = new CRMEntity();
             $do_feed_queue = new LiveFeedQueue();
             $do_process_plugins = new CRMPluginProcessor();
             //delete code for the record goes here
             // process before delete plugin
             $do_process_plugins->process_action_plugins($module_id, null, 5, $id);
             if (strlen($do_process_plugins->get_error()) > 2) {
                 echo $do_process_plugins->get_error();
             } else {
                 $this->delete_record($id, $module);
                 $do_data_history->add_history($id, $module_id, 'delete');
                 // Add to feed
                 $feed_other_assigne = array();
                 $entity_assigned_to = $crm_entity->get_assigned_to_id($id, $module);
                 if (is_array($entity_assigned_to) && sizeof($entity_assigned_to) > 0) {
                     if (array_key_exists("idgroup", $entity_assigned_to) && $entity_assigned_to["idgroup"]) {
                         $feed_other_assigne = array("related" => "group", "data" => array("key" => "oldgroup", "val" => (int) $entity_assigned_to["idgroup"]));
                     }
                 }
                 $record_identity = $crm_entity->get_entity_identifier($id, $module);
                 $do_feed_queue->add_feed_queue($id, $module_id, $record_identity, 'delete', $feed_other_assigne);
                 // process after delete plugin
                 $do_process_plugins->process_action_plugins($module_id, null, 5, $id);
                 echo '1';
             }
         } else {
             echo '0';
         }
     } else {
         echo '0';
     }
 }
예제 #11
0
 /**
  * function to map organization to contact while importing
  * checks if the organization already exists else add a new one
  * @param string $organization_name
  * @param object $import_object
  * @param array $data
  * @return integer idorganization
  */
 public function map_contact_organization($organization_name, $import_object, $data)
 {
     $qry = "\n\t\tselect idorganization \n\t\tfrom organization \n\t\twhere organization_name = ?\n\t\tAND deleted = 0\n\t\tAND iduser ="******"do_user"]->iduser;
     $stmt = $this->getDbConnection()->executeQuery($qry, array(trim($organization_name)));
     if ($stmt->rowCount() > 0) {
         $rs = $stmt->fetch();
         return $rs["idorganization"];
     } else {
         if (strlen($organization_name) > 2) {
             $mapped_fields = $import_object->get_mapped_fields();
             $do_organization = new Organization();
             $do_organization->insert("organization", array("organization_name" => CommonUtils::purify_input($organization_name), "iduser" => $_SESSION["do_user"]->iduser));
             $idorganization = $do_organization->getInsertId();
             $q_upd = "\n\t\t\t\tupdate `organization`\n\t\t\t\tset `added_on` = ?\n\t\t\t\twhere `idorganization` = ?";
             $do_organization->query($q_upd, array(date("Y-m-d H:i:s"), $idorganization));
             $do_organization->insert("organization_custom_fld", array("idorganization" => $idorganization));
             $mapped_fields = $import_object->get_mapped_fields();
             if (array_search("cnt_mail_street", $mapped_fields) !== false) {
                 $org_bill_address = $data[array_search("cnt_mail_street", $mapped_fields)];
             } else {
                 $org_bill_address = '';
             }
             if (array_search("cnt_mail_pobox", $mapped_fields) !== false) {
                 $org_bill_pobox = $data[array_search("cnt_mail_pobox", $mapped_fields)];
             } else {
                 $org_bill_pobox = '';
             }
             if (array_search("cnt_mailing_city", $mapped_fields) !== false) {
                 $org_bill_city = $data[array_search("cnt_mailing_city", $mapped_fields)];
             } else {
                 $org_bill_city = '';
             }
             if (array_search("cnt_mailing_state", $mapped_fields) !== false) {
                 $org_bill_state = $data[array_search("cnt_mailing_state", $mapped_fields)];
             } else {
                 $org_bill_state = '';
             }
             if (array_search("cnt_mailing_postalcode", $mapped_fields) !== false) {
                 $org_bill_postalcode = $data[array_search("cnt_mailing_postalcode", $mapped_fields)];
             } else {
                 $org_bill_postalcode = '';
             }
             if (array_search("cnt_mailing_country", $mapped_fields) !== false) {
                 $org_bill_country = $data[array_search("cnt_mailing_country", $mapped_fields)];
             } else {
                 $org_bill_country = '';
             }
             $do_organization->insert("organization_address", array("idorganization" => $idorganization, "org_bill_address" => CommonUtils::purify_input($org_bill_address), "org_bill_pobox" => CommonUtils::purify_input($org_bill_pobox), "org_bill_city" => CommonUtils::purify_input($org_bill_city), "org_bill_state" => CommonUtils::purify_input($org_bill_state), "org_bill_postalcode" => CommonUtils::purify_input($org_bill_postalcode), "org_bill_country" => CommonUtils::purify_input($org_bill_country)));
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idorganization, 6, 'add');
             $do_data_history->free();
             return $idorganization;
         } else {
             return 0;
         }
     }
 }