Beispiel #1
0
 /**   
  * Event function to update the group
  * Also updates the related member information of the group
  * @param object $evctl
  * @see modules/Settings/group_edit.php
  */
 public function eventEditGroup(EventControler $evctl)
 {
     $permission = $_SESSION["do_user"]->is_admin == 1 ? true : false;
     if (true === $permission) {
         if ($evctl->idgroup != '' && $evctl->group_name) {
             $qry = "\n\t\t\t\tUPDATE `" . $this->getTable() . "` \n\t\t\t\tset `group_name` = ?,\n\t\t\t\t`description` = ?\n\t\t\t\twhere `idgroup` = ? LIMIT 1";
             $this->query($qry, array(CommonUtils::purify_input($evctl->group_name), CommonUtils::purify_input($evctl->description), $evctl->idgroup));
             if (is_array($evctl->select_to) && count($evctl->select_to) > 0) {
                 $do_group_user_rel = new GroupUserRelation();
                 $do_group_user_rel->update_group_related_to_user($evctl->select_to, $evctl->idgroup);
             }
             $_SESSION["do_crm_messages"]->set_message('success', _('Group has been updated successfully !'));
             $dis = new Display($evctl->next_page);
             $dis->addParam("sqrecord", $evctl->idgroup);
             $evctl->setDisplayNext($dis);
         } else {
             $_SESSION["do_crm_messages"]->set_message('error', _('Unable to update the group, either group name or id is missing !'));
             $dis = new Display($evctl->error_page);
             $evctl->setDisplayNext($dis);
         }
     } else {
         $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to edit record !'));
         $next_page = NavigationControl::getNavigationLink("Settings", "index");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     }
 }
 /**
  * event function to add the invoice payment 
  * @param object $evctl
  */
 public function eventAjaxAddInvoicePayment(EventControler $evctl)
 {
     $err = false;
     $error_code = 0;
     if (trim($evctl->payment_date) == '') {
         $err = true;
         $error_code = 1;
     } elseif (trim($evctl->ref_num) == '') {
         $err = true;
         $error_code = 2;
     } elseif ((int) FieldType30::convert_before_save(trim($evctl->amount)) == 0) {
         $err = true;
         $error_code = 3;
     } elseif (true === $this->is_payment_more_than_due($evctl->idinvoice, FieldType30::convert_before_save(trim($evctl->amount)))) {
         $err = true;
         $error_code = 4;
     }
     if (true === $err) {
         echo $error_code;
     } else {
         $payment_date = FieldType9::convert_before_save($evctl->payment_date);
         $payment_mode = $evctl->payment_mode;
         $amount = FieldType30::convert_before_save($evctl->amount);
         $ref_num = CommonUtils::purify_input($evctl->ref_num);
         $additional_note = CommonUtils::purify_input($evctl->additional_note);
         $idinvoice = (int) $evctl->idinvoice;
         // add to paymentlog
         $do_paymentlog = new Paymentlog();
         $do_paymentlog->addNew();
         $do_paymentlog->date_added = $payment_date;
         $do_paymentlog->amount = $amount;
         $do_paymentlog->ref_num = $ref_num;
         $do_paymentlog->idpayment_mode = $payment_mode;
         $do_paymentlog->add();
         $idpaymentlog = $do_paymentlog->getInsertId();
         // add to invoice payment
         $this->addNew();
         $this->idinvoice = $idinvoice;
         $this->idpaymentlog = $idpaymentlog;
         $this->additional_note = $additional_note;
         $this->iduser = $_SESSION["do_user"]->iduser;
         $this->add();
         $qry = "\n\t\t\tselect * from `payment_mode` where `idpayment_mode` = ?\n\t\t\t";
         $stmt = $this->getDbConnection()->executeQuery($qry, array($evctl->payment_mode));
         $data = $stmt->fetch();
         $payment_mode_name = $data['mode_name'];
         $html = '';
         $html .= '<tr>';
         $html .= '<td>' . FieldType9::display_value($payment_date) . '</td>';
         $html .= '<td>' . FieldType30::display_value($amount) . '</td>';
         $html .= '<td>' . FieldType1::display_value($ref_num) . '</td>';
         $html .= '<td>' . FieldType1::display_value($payment_mode_name) . '</td>';
         $html .= '<td>' . _('charge') . '</td>';
         $html .= '<td>' . nl2br($additional_note) . '</td>';
         $html .= '</tr>';
         $invoice_payments = new InvoicePayments();
         $due_amount = FieldType30::display_value($invoice_payments->get_due_amount($idinvoice));
         echo json_encode(array('html' => $html, 'due_amount' => $due_amount));
     }
 }
Beispiel #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;
         }
     }
 }
Beispiel #4
0
 /**
  * event function to add a new role
  * @param object $evctl
  */
 public function eventAddNewRole(EventControler $evctl)
 {
     $permission = $_SESSION["do_user"]->is_admin == 1 ? true : false;
     if (true === $permission) {
         if ($evctl->rolename != '' && $evctl->parentrole != '') {
             $role_detail = $this->get_role_detail($evctl->parentrole);
             if (is_array($role_detail) && count($role_detail) > 0) {
                 $depth_lookup = $role_detail["depth"] + 1;
                 $qry = "select max(idrole) as max_role from `role`";
                 $stmt = $this->getDbConnection()->executeQuery($qry);
                 $data = $stmt->fetch();
                 $max_role = $data["max_role"];
                 if ($max_role != '') {
                     $role_int = str_replace("N", "", $max_role);
                     $new_role_int = $role_int + 1;
                     $new_role = "N" . $new_role_int;
                     $new_parent_role = $role_detail["parentrole"] . "::" . $new_role;
                     $this->insert($this->getTable(), array("idrole" => $new_role, "rolename" => CommonUtils::purify_input($evctl->rolename), "parentrole" => $new_parent_role, "depth" => $depth_lookup, "editable" => 1));
                     // Adding role profile relation
                     $profiles = $evctl->select_to;
                     foreach ($profiles as $idprofile) {
                         $do_role_prof_rel = new RoleProfileRelation();
                         $do_role_prof_rel->addNew();
                         $do_role_prof_rel->idrole = $new_role;
                         $do_role_prof_rel->idprofile = $idprofile;
                         $do_role_prof_rel->add();
                         $do_role_prof_rel->free();
                     }
                     $dis = new Display($evctl->next_page);
                     $dis->addParam("sqrecord", $idprofile);
                     $evctl->setDisplayNext($dis);
                 }
             }
         }
     } else {
         $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to add record !'));
         $next_page = NavigationControl::getNavigationLink("Settings", "index");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     }
 }
Beispiel #5
0
 /**
  * function to format the import data before saving
  * @param integer $field_type
  * @param mix value
  * @return the formatted value
  * @TODO format data for other types, right now its done only for checkbox( fieldtype 3 ) and date( fieldtype 9)
  */
 public function format_data_before_save($field_type, $val)
 {
     if ($field_type == 3) {
         if ($val == '') {
             return 0;
         }
         if (strtolower($val) == 'yes') {
             return 1;
         } elseif (strtolower($val) == 'no') {
             return 0;
         } else {
             return CommonUtils::purify_input($val);
         }
     } elseif ($field_type == 9) {
         if ($val == '') {
             return $val;
         }
         return date("Y-m-d", strtotime($val));
     } else {
         return $val;
     }
 }
Beispiel #6
0
 /**
  * function to edit the custom field
  * @param object $evctl
  * @see popups/edit_custom_field_modal.php
  */
 public function eventEditCustomField(EventControler $evctl)
 {
     $idfields = (int) $evctl->idfields_ed;
     $update_data = false;
     if ($idfields > 0) {
         $this->getId($idfields);
         if ($this->getNumRows() > 0) {
             $update_data = true;
         } else {
             $update_data = false;
             $_SESSION["do_crm_messages"]->set_message('error', _('Record does not exit.'));
         }
     } else {
         $update_data = false;
         $_SESSION["do_crm_messages"]->set_message('error', _('Record does not exit.'));
     }
     if ($update_data === true) {
         $custom_field_type = $evctl->custom_field_type_ed;
         $req = $evctl->cf_req_ed;
         $field_validation = array();
         $is_required = false;
         if ($req == 'on') {
             $is_required = true;
             $field_validation["required"] = true;
         }
         switch ($custom_field_type) {
             case 1:
                 if ($is_required === true) {
                     if ($evctl->cf_max_len_ed != '' || (int) $evctl->cf_max_len_ed > 0) {
                         $field_validation["maxlength"] = (int) $evctl->cf_max_len_ed;
                     }
                     if ($evctl->cf_min_len_ed != '' || (int) $evctl->cf_min_len_ed > 0) {
                         $field_validation["minlength"] = (int) $evctl->cf_min_len_ed;
                     }
                 }
                 break;
             case 5:
                 $pick_values = $evctl->cf_pick_ed;
                 $not_equal = $evctl->cf_pick_notequal_ed;
                 if ($is_required === true) {
                     $field_validation["notEqual"] = $not_equal;
                 }
                 break;
             case 6:
                 $pick_values = $evctl->cf_pick_ed;
                 break;
         }
         if (count($field_validation) > 0) {
             $field_validation_entry = json_encode($field_validation);
         } else {
             $field_validation_entry = '';
         }
         $qry_update = "\n\t\t\tupdate " . $this->getTable() . " \n\t\t\tset `field_label` = ?,\n\t\t\t`field_validation` = ?\n\t\t\twhere idfields = ?";
         $this->query($qry_update, array(CommonUtils::purify_input($evctl->cf_label_ed), $field_validation_entry, $idfields));
         if ($custom_field_type == 5 || $custom_field_type == 6) {
             //$pick_values_seperated = explode(PHP_EOL,$evctl->cf_pick);
             $pick_values_seperated = preg_split('/[\\r\\n]+/', $evctl->cf_pick_ed, -1, PREG_SPLIT_NO_EMPTY);
             $do_combo_values = new ComboValues();
             $do_combo_values->update_combo_values($idfields, $pick_values_seperated);
         }
         $_SESSION["do_crm_messages"]->set_message('success', _('Custom field updated successfully !'));
     }
 }
 /**
  * function getting the field value from the event controller object depending on the field type
  * if needed do the field conversion
  * @param object $do_crm_fields
  * @param object $evctl
  */
 public function convert_field_value_onsave($do_crm_fields, $evctl, $action = 'add')
 {
     $fieldobject = 'FieldType' . $do_crm_fields["field_type"];
     $field_name = $do_crm_fields["field_name"];
     if ($do_crm_fields["field_type"] == 3) {
         if ($evctl->{$field_name} == "on") {
             $value = 1;
         } else {
             $value = 0;
         }
     } elseif ($do_crm_fields["field_type"] == 6 || $do_crm_fields["field_type"] == 9 || $do_crm_fields["field_type"] == 10 || $do_crm_fields["field_type"] == 30) {
         $value = $fieldobject::convert_before_save($evctl->{$field_name});
     } elseif ($do_crm_fields["field_type"] == 11) {
         $value = md5($evctl->{$field_name});
     } elseif ($do_crm_fields["field_type"] == 12) {
         if ($_FILES[$field_name]['tmp_name'] != '') {
             $file_size = $_FILES[$field_name]['size'];
             if ($action == 'edit') {
                 $hidden_file_name = 'upd_' . $field_name;
                 $current_file_name_in_db = $evctl->{$hidden_file_name};
                 FieldType12::remove_thumb($current_file_name_in_db);
                 $value = FieldType12::upload_avatar($_FILES[$field_name]['tmp_name'], $_FILES[$field_name]['name']);
                 $value["field_type"] = 12;
                 $value["file_size"] = $file_size;
             } else {
                 $value = FieldType12::upload_avatar($_FILES[$field_name]['tmp_name'], $_FILES[$field_name]['name']);
                 $value["field_type"] = 12;
                 $value["file_size"] = $file_size;
             }
         } else {
             if ($action == 'edit') {
                 $hidden_file_name = 'upd_' . $field_name;
                 $current_file_name_in_db = $evctl->{$hidden_file_name};
                 $value = $current_file_name_in_db;
             } else {
                 $value = '';
             }
         }
     } elseif ($do_crm_fields["field_type"] == 15) {
         $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;
         }
         $value = array("field_type" => $do_crm_fields["field_type"], "value" => $fld_value, "assigned_to_as_group" => $assigned_to_as_group, "group_id" => $group_id);
     } elseif ($do_crm_fields["field_type"] == 165) {
         $field_name = $do_crm_fields["field_name"];
         $value_165 = array();
         $cnt = count($evctl->{$field_name});
         if ($cnt > 0) {
             $i = 1;
             foreach ($evctl->{$field_name} as $key => $val) {
                 $tax_value_fld = $field_name . '_' . $i;
                 $value_165[] = array("tax_name" => $val, "tax_value" => $evctl->{$tax_value_fld});
                 $i++;
             }
             $value = array("field_type" => $do_crm_fields["field_type"], "value" => $value_165);
         }
     } else {
         $value = $evctl->{$field_name};
     }
     if (is_array($value)) {
         return $value;
     } else {
         return CommonUtils::purify_input($value);
     }
 }
Beispiel #8
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;
         }
     }
 }
Beispiel #9
0
 /**
  * event function save tax setting
  * @param object $evctl
  */
 function eventSaveTaxData(EventControler $evctl)
 {
     $permission = $_SESSION["do_user"]->is_admin == 1 ? true : false;
     if (true === $permission) {
         $tax_type = $evctl->tax_type;
         $tax_name = $evctl->tax_name;
         $tax_value = $evctl->tax_value;
         if ($tax_name == '' || $tax_value == '') {
             $_SESSION["do_crm_messages"]->set_message('error', _('Missing tax name or tax value ! '));
             $next_page = NavigationControl::getNavigationLink("Settings", "tax_settings");
             $dis = new Display($next_page);
             $evctl->setDisplayNext($dis);
         } else {
             if ($tax_type == 'ps') {
                 $this->insert("`product_service_tax`", array("tax_name" => CommonUtils::purify_input($evctl->tax_name), "tax_value" => CommonUtils::purify_input($evctl->tax_value)));
                 $id = $this->getInsertId();
                 $this->query("select * from `product_service_tax` where idproduct_service_tax = ?", array($id));
                 $this->next();
                 $return_array = array("id" => $id, "tax_name" => $this->tax_name, "tax_value" => $this->tax_value);
             } else {
                 $this->insert("`shipping_handling_tax`", array("tax_name" => CommonUtils::purify_input($evctl->tax_name), "tax_value" => CommonUtils::purify_input($evctl->tax_value)));
                 $id = $this->getInsertId();
                 $this->query("select * from `shipping_handling_tax` where idshipping_handling_tax = ?", array($id));
                 $this->next();
                 $return_array = array("id" => $id, "tax_name" => $this->tax_name, "tax_value" => $this->tax_value);
             }
             echo json_encode($return_array);
         }
     }
 }
Beispiel #10
0
 /**
  * Event method to update the profile name and description
  * @param object $evctl
  */
 public function eventRenameProfile(EventControler $evctl)
 {
     if ($evctl->id != '') {
         $this->cleanValues();
         $this->profilename = CommonUtils::purify_input($evctl->profilename);
         $this->description = CommonUtils::purify_input($evctl->description);
         $this->update((int) $evctl->id);
     }
 }
Beispiel #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;
         }
     }
 }
Beispiel #12
0
 /**
  * event function to update the notes
  * @param object $evctl
  */
 function eventAjaxUpdateNotes(\EventControler $evctl)
 {
     if ((int) $evctl->idnotes > 0) {
         $this->getId((int) $evctl->idnotes);
         if ($_SESSION["do_cpaneluser"]->idcpanel_user === $this->idcpanel_user) {
             $notes = \CommonUtils::purify_input($evctl->notes_edit_data);
             $this->cleanValues();
             $this->notes = $notes;
             $this->update((int) $evctl->idnotes);
             $notes = \CommonUtils::format_display_text($notes);
             echo \FieldType200::display_value($notes);
         }
     }
 }
Beispiel #13
0
 /**
  * event function to update the notes
  * @param object $evctl
  */
 function eventAjaxUpdateNotes(EventControler $evctl)
 {
     if ((int) $evctl->idnotes > 0 && $_SESSION["do_crm_action_permission"]->action_permitted('edit', 8, (int) $evctl->idnotes) === true) {
         $notes = CommonUtils::purify_input($evctl->notes_edit_data);
         $this->cleanValues();
         $this->notes = $notes;
         $this->update((int) $evctl->idnotes);
         /*if (strlen($notes) > 200) {
         			$notes = substr($notes, 0, 200);
         			$notes .= '&nbsp;<a href="#" onclick="view_more_notes(\''.$this->idnotes.'\'); return false;">more...</a>';
         		}*/
         $notes = CommonUtils::format_display_text($notes);
         echo FieldType200::display_value($notes);
     }
 }