Пример #1
0
<?php

// Copyright SQCRM. For licensing, reuse, modification and distribution see license.txt
/**
* Cronjob to delete the old feeds. With some moderate number of users within the system there will be
* a lot of feeds and over a period of time the table size will increase exponentially. So its better to 
* clean the the feed table on regular interval. By default in includes/sqcrm.conf.inc.php the days to keep is 90 days.
* We can change the value as we want.
* Usually it should run every day once.
* $GLOBALS['cfg_full_path'] is the path to the CRM root so that the cron job could be 
* set outside web access directory which is recomended
* @author Abhik Chakraborty
*/
$GLOBALS['cfg_full_path'] = '/var/www/sqcrm/';
include_once $GLOBALS['cfg_full_path'] . 'config.php';
$do_live_feed_queue = new LiveFeedQueue();
$do_live_feed_queue->get_feeds_to_be_deleted();
if ($do_live_feed_queue->getNumRows() > 0) {
    while ($do_live_feed_queue->next()) {
        $do_live_feed_queue->delete_feed_queue($do_live_feed_queue->idfeed_queue);
    }
}
echo "Total number of old feeds deleted " . $do_live_feed_queue->getNumRows();
Пример #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
 /**
  * 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 !'));
     }
 }
Пример #4
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 !'));
     }
 }
Пример #5
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) !'));
     }
 }
Пример #6
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';
     }
 }
Пример #7
0
 /**
  * add feed for the mentioned notes
  * @param integer $idnotes
  * @param string $note_content
  * @param integer $related_module_id
  * @param integer $sqcrm_record_id
  */
 public function add_mentions_feed($idnotes, $note_content, $related_module_id, $sqcrm_record_id)
 {
     if ($idnotes > 0) {
         $mentioned_feed_receiptents = array();
         preg_match_all("/(^|[^@\\w])@(\\w{1,15})\\b/im", $note_content, $mentioned_users);
         if (is_array($mentioned_users) && array_key_exists(2, $mentioned_users) && count($mentioned_users[2]) > 0) {
             $do_user = new \User();
             $active_users = $do_user->get_active_users();
             $current_user = 0;
             $active_users_key_as_username = array();
             foreach ($active_users as $key => $users) {
                 if ($users["iduser"] == $current_user) {
                     continue;
                 }
                 $active_users_key_as_username[$users["user_name"]] = array("iduser" => $users["iduser"], "firstname" => $users["firstname"], "lastname" => $users["lastname"], "email" => $users["email"]);
             }
             foreach ($mentioned_users[2] as $key => $val) {
                 if (array_key_exists($val, $active_users_key_as_username)) {
                     $mentioned_feed_receiptents[] = $active_users_key_as_username[$val["iduser"]];
                 }
             }
             if (is_array($mentioned_feed_receiptents) && count($mentioned_feed_receiptents) > 0) {
                 $do_feed_queue = new \LiveFeedQueue();
                 $do_crm_entity = new \CRMEntity();
                 $do_module = new \Module();
                 $do_module->getId($related_module_id);
                 $identifier = $do_crm_entity->get_entity_identifier($sqcrm_record_id, $do_module->name);
                 $related_identifier_data = array("related_identifier" => '', "related_identifier_idrecord" => $idnotes, "related_identifier_idmodule" => 8);
                 $do_feed_queue->add_feed_queue($sqcrm_record_id, $related_module_id, $identifier, 'note_mention', $mentioned_feed_receiptents, $related_identifier_data);
             }
         }
     }
 }