Ejemplo n.º 1
0
 public function edit_post()
 {
     $data = $this->data;
     //取得公用數據
     //基本post欄位
     $contactid_Num = $this->input->post('contactid_Num', TRUE);
     $status_process_Num = $this->input->post('status_process_Num');
     //建構Contact物件,並且更新
     $Contact = new Contact(['contactid_Num' => $contactid_Num, 'status_process_Num' => $status_process_Num]);
     $Contact->update(['db_update_Arr' => ['status_process']]);
     //送出成功訊息
     $this->load->model('Message');
     $this->Message->show(['message' => '設定成功', 'url' => 'admin/base/contact/contact/tablelist']);
 }
Ejemplo n.º 2
0
 /**
  * Update contact
  *
  * @param int   $id             Id of contact to update
  * @param array $request_data   Datas   
  * @return int 
  * 
  * @url	PUT contact/{id}
  */
 function put($id, $request_data = NULL)
 {
     if (!DolibarrApiAccess::$user->rights->societe->contact->creer) {
         throw new RestException(401);
     }
     $result = $this->contact->fetch($id);
     if (!$result) {
         throw new RestException(404, 'Contact not found');
     }
     if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) {
         throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
     }
     foreach ($request_data as $field => $value) {
         $this->contact->{$field} = $value;
     }
     if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) {
         return $this->get($id);
     }
     return false;
 }
Ejemplo n.º 3
0
 public function testContactPut()
 {
     Client::relateIQ(GlobalVar::KEY, GlobalVar::SECRET);
     $contact = new Contact(["id" => "551c7102e4b0e9a403dfb098"]);
     $contact->name("Juan TorrezUpdated3");
     $res = $contact->update();
     $this->assertInstanceOf('Contact', $res);
     $contact2 = new Contact(["id" => $res->id()]);
     $this->assertEquals($contact->name(), $contact2->name());
     $this->assertEquals("Juan TorrezUpdated3", $contact2->name());
 }
Ejemplo n.º 4
0
        } else {
            if (isset($_POST["restore"])) {
                $contact->check($_POST["id"], DELETE);
                if ($contact->restore($_POST)) {
                    Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
                }
                $contact->redirectToList();
            } else {
                if (isset($_POST["purge"])) {
                    $contact->check($_POST["id"], PURGE);
                    if ($contact->delete($_POST, 1)) {
                        Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
                    }
                    $contact->redirectToList();
                } else {
                    if (isset($_POST["update"])) {
                        $contact->check($_POST["id"], UPDATE);
                        if ($contact->update($_POST)) {
                            Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
                        }
                        Html::back();
                    } else {
                        Html::header(Contact::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "management", "contact");
                        $contact->display(array('id' => $_GET["id"]));
                        Html::footer();
                    }
                }
            }
        }
    }
}
Ejemplo n.º 5
0
 function updatecontract($_post)
 {
     $user->id = $this->getuser();
     $profile = new Contact($user->id);
     return $profile->update($_post);
 }
	/**
     *      Update parameters of third party
     *      @param      id              			id societe
     *      @param      user            			Utilisateur qui demande la mise a jour
     *      @param      call_trigger    			0=non, 1=oui
     *		@param		allowmodcodeclient			Inclut modif code client et code compta
     *		@param		allowmodcodefournisseur		Inclut modif code fournisseur et code compta fournisseur
     *      @return     int             			<0 si ko, >=0 si ok
     */
    function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0)
    {
    	$result = parent::update($id, $user, $call_trigger, $allowmodcodeclient, $allowmodcodefournisseur);

    	return $result;
    }
Ejemplo n.º 7
0
/**
 * Update a contact
 *
 * @param	array		$authentication		Array of authentication information
 * @param	Contact		$contact		    Contact
 * @return	array							Array result
 */
function updateContact($authentication, $contact)
{
    global $db, $conf, $langs;
    $now = dol_now();
    dol_syslog("Function: updateContact login="******"Contact id is mandatory.";
    }
    if (!$error) {
        $objectfound = false;
        include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
        $object = new Contact($db);
        $result = $object->fetch($contact['id']);
        if (!empty($object->id)) {
            $objectfound = true;
            $object->firstname = $contact['firstname'];
            $object->lastname = $contact['lastname'];
            $object->address = $contact['address'];
            $object->zip = $contact['zip'];
            $object->town = $contact['town'];
            $object->country_id = $contact['country_id'];
            if ($contact['country_code']) {
                $object->country_id = getCountry($contact['country_code'], 3);
            }
            $object->province_id = $contact['province_id'];
            $object->phone_pro = $contact['phone_pro'];
            $object->phone_perso = $contact['phone_perso'];
            $object->phone_mobile = $contact['phone_mobile'];
            $object->fax = $contact['fax'];
            $object->email = $contact['email'];
            $object->civility_id = $contact['civility_id'];
            $object->poste = $contact['poste'];
            $object->statut = $contact['statut'];
            //Retreive all extrafield for contact
            // fetch optionals attributes and labels
            $extrafields = new ExtraFields($db);
            $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true);
            foreach ($extrafields->attribute_label as $key => $label) {
                $key = 'options_' . $key;
                $object->array_options[$key] = $contact[$key];
            }
            $db->begin();
            $result = $object->update($contact['id'], $fuser);
            if ($result <= 0) {
                $error++;
            }
        }
        if (!$error && $objectfound) {
            $db->commit();
            $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $object->id);
        } elseif ($objectfound) {
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $object->error;
        } else {
            $error++;
            $errorcode = 'NOT_FOUND';
            $errorlabel = 'Contact id=' . $contact['id'] . ' cannot be found';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
Ejemplo n.º 8
0
<?php

/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
// Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
/**
 * unsubscribe a user 
 */
include_once "config.php";
$idcontact = (int) $_GET['idc'];
$iduser = (int) trim($_GET['idu']);
$do_contact = new Contact();
//$do_contact->getId($idcontact);
$do_user = new User();
$do_user->getId($iduser);
$do_user->sessionPersistent('user_unsub', 'unsubscribe_message.php', TTL_OFUZ);
$do_contact->query("SELECT * \n                            FROM  contact \n                            WHERE contact.idcontact=" . $idcontact . " AND contact.iduser = "******"SELECT contact.*\n                            FROM contact, contact_sharing \n                            WHERE `contact_sharing`.`idcoworker` = " . $iduser . "\n                            AND contact.idcontact = contact_sharing.idcontact\n\t\t\t\t\t\t\tAND contact.idcontact=" . $idcontact);
}
if ($do_contact->getNumRows() == 1 && $do_user->getNumRows() == 1) {
    $do_contact->email_optout = 'y';
    $do_contact->update();
    $do_workfeed_uns = new WorkFeedContactUnsubscibeEmails();
    $do_workfeed_uns->addUnsubscribeEmailWorkfeed($do_contact);
}
//$do_contact->sessionPersistent('do_contact', 'unsubscribe_messaage.php', OFUZ_TTL);
header("Location: /unsubscribe_message.php");
exit;
 function import2Dolibarr($object, $typeimport)
 {
     global $conf;
     global $langs;
     $this->process_msg = '';
     $error = 0;
     $fp = @fopen($this->filename, "r");
     if ($fp) {
         switch ($object) {
             case 'ImportStock':
                 $doliprod = new Product($this->db);
                 $i = 0;
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $doliprod->id = '';
                     $i++;
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     if ($conf->global->IMPORT_BARCODE) {
                         $ligne[0] = $this->get_product_by_barcode($ligne[0]);
                     }
                     if ($doliprod->fetch('', $ligne[0]) <= 0) {
                         $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n";
                     } else {
                         $pid = $doliprod->id;
                         $doliprod->ref = $ligne[0];
                         $entrepot = $ligne[1];
                         $newstock = $ligne[2];
                         $price = $ligne[3];
                         if ($conf->global->IMPORT_TOTAL_STOCK) {
                             $doliprod->load_stock();
                             dol_syslog("stock produit " . $doliprod->stock_warehouse[$entrepot]->real . " entrepot " . $entrepot . " " . $doliprod->stock_reel, LOG_DEBUG);
                             // correction de stock
                             $delta = 0;
                             if ($newstock > $doliprod->stock_warehouse[$entrepot]->real) {
                                 $delta = $newstock - $doliprod->stock_warehouse[$entrepot]->real;
                                 $sens = 0;
                             } elseif ($newstock < $doliprod->stock_warehouse[$entrepot]->real) {
                                 $delta = $doliprod->stock_warehouse[$entrepot]->real - $newstock;
                                 $sens = 1;
                             }
                             if ($delta) {
                                 $res = $doliprod->correct_stock($this->user, $entrepot, $delta, $sens, $langs->trans("StockCorrection"), $price);
                                 if ($res < 0) {
                                     $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n";
                                     $error++;
                                 }
                             }
                             dol_syslog("maj stock delta = " . $delta . " sens " . $sens, LOG_DEBUG);
                         } else {
                             $res = $doliprod->correct_stock($this->user, $entrepot, abs($newstock), $newstock > 0 ? 0 : 1, $langs->trans("StockCorrection"), $price);
                             if ($res < 0) {
                                 $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n";
                                 $error++;
                             }
                         }
                     }
                 }
                 break;
             case 'ImportProduct':
                 //$doliprod = new Product($this->db);
                 $i = 0;
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $i++;
                     $doliprod = new Product($this->db);
                     $doliprod->id = '';
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     if ($doliprod->fetch('', $ligne[0]) < 0) {
                         $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n";
                     } else {
                         $pid = $doliprod->id;
                         $doliprod->ref = $ligne[0];
                         if (!empty($ligne[1])) {
                             $doliprod->libelle = $ligne[1];
                         }
                         if (!empty($ligne[2])) {
                             $doliprod->status = $ligne[2];
                         }
                         $doliprod->status_buy = 1;
                         if (!empty($ligne[3])) {
                             $doliprod->description = $ligne[3];
                         }
                         if (!empty($ligne[4])) {
                             $doliprod->price = $ligne[4];
                         }
                         if (!empty($ligne[5])) {
                             $doliprod->tva_tx = $ligne[5];
                         }
                         if (!empty($ligne[6])) {
                             $doliprod->weight = $ligne[6];
                         }
                         if (!empty($ligne[7])) {
                             $doliprod->volume = $ligne[7];
                         }
                         if (!empty($ligne[9])) {
                             $doliprod->barcode = $ligne[9];
                         }
                         if (!empty($ligne[9])) {
                             $doliprod->barcode_type = dol_getIdFromCode($this->db, $ligne[10], 'c_barcode_type', 'libelle', 'rowid');
                         }
                         if (!empty($ligne[10])) {
                             $doliprod->type = $ligne[11];
                         }
                         $doliprod->price_base_type = 'HT';
                         $this->db->begin;
                         switch ($typeimport) {
                             case 'C':
                                 if ($pid > 0) {
                                     if ($doliprod->update($pid, $this->user) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     }
                                     if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     }
                                 } else {
                                     if ($doliprod->create($this->user) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     } else {
                                         // image et code barre
                                         if ($ligne[8]) {
                                             $this->add_photo_web($conf->produit->dir_output, $ligne[8], $doliprod->id);
                                         }
                                         /*if ($ligne[9]) {
                                         			if ($doliprod->setValueFrom('fk_barcode_type', 2) < 0){
                                         				$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; // TODO paramétrer
                                         				$error++;
                                         			}
                                         			if ($doliprod->setValueFrom('barcode', $ligne[9]) < 0 ){
                                         				$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n";
                                         				$error++;
                                         			}
                                         		}*/
                                     }
                                 }
                                 break;
                                 /*case 'M':
                                 		if ($pid>0) 
                                 		{
                                 			if ($doliprod->update($pid, $this->user) < 0){
                                 				$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                                 				$error++;
                                 			}
                                 			if (version_compare(DOL_VERSION, 3.5) >= 0){
                                 				if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                                 					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                                 					$error++;
                                 				}
                                 			}
                                 			else{
                                 				if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                                 					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                                 					$error++;
                                 				}
                                 			}
                                 		}
                                 		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n";
                                 		break;*/
                             /*case 'M':
                             		if ($pid>0) 
                             		{
                             			if ($doliprod->update($pid, $this->user) < 0){
                             				$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                             				$error++;
                             			}
                             			if (version_compare(DOL_VERSION, 3.5) >= 0){
                             				if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                             					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                             					$error++;
                             				}
                             			}
                             			else{
                             				if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                             					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                             					$error++;
                             				}
                             			}
                             		}
                             		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n";
                             		break;*/
                             case 'D':
                                 if ($pid > 0) {
                                     if ($doliprod->delete($pid) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductDelete", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     }
                                 } else {
                                     $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrProdNoExist", $ligne[0]) . "\n";
                                 }
                         }
                         if (!$error) {
                             $this->db->commit();
                         } else {
                             $this->db->rollback();
                         }
                     }
                 }
                 // while
                 break;
             case 'ImportThirtdparty':
                 $i = 0;
                 //$societe = new Societe($this->db);
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $i++;
                     $societe = new Societe($this->db);
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     if (!$ligne[0]) {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n";
                         continue;
                     }
                     // vérifier par code_client
                     if ($ligne[13]) {
                         $sid = $this->get_socbyclientcode($ligne[13]);
                     } else {
                         if ($ligne[14]) {
                             $sid = $this->get_socbysuplliercode($ligne[14]);
                         }
                     }
                     if ($sid > 0) {
                         $societe->fetch($sid);
                     } else {
                         $sid = $societe->fetch('', $ligne[0]);
                     }
                     if ($ligne[12]) {
                         $pid = dol_getIdFromCode($this->db, $ligne[12], "c_pays", "code", "rowid");
                     } else {
                         $pid = '';
                     }
                     if ($pid <= 0) {
                         $pid = '';
                     }
                     $did = '';
                     $societe->id = $sid;
                     $societe->name = $ligne[0];
                     $societe->particulier = 0;
                     //Société
                     $societe->address = $ligne[1] . "\n" . $ligne[2] . "\n" . $ligne[3];
                     $societe->zip = $ligne[4];
                     $societe->town = $ligne[5];
                     $societe->state_id = $did;
                     if ($ligne[12]) {
                         $societe->country_code = $ligne[12];
                     }
                     $societe->country_id = $pid;
                     dol_syslog("codes {$pid} " . $lige[12], LOG_DEBUG);
                     $societe->phone = $ligne[6];
                     $societe->fax = $ligne[7];
                     $societe->email = $ligne[8];
                     $societe->url = $ligne[9];
                     $societe->idprof1 = $ligne[10];
                     switch ($ligne[11]) {
                         case '0':
                             $societe->fournisseur = 0;
                             $societe->client = $ligne[11];
                             break;
                         case '1':
                             $societe->fournisseur = 0;
                             $societe->client = $ligne[11];
                             break;
                         case '2':
                             $societe->fournisseur = 0;
                             $societe->client = $ligne[11];
                             break;
                         case '10':
                             $societe->client = 0;
                             $societe->fournisseur = 1;
                             break;
                         default:
                             break;
                     }
                     if ($ligne[13]) {
                         $societe->code_client = $ligne[13];
                     }
                     if ($ligne[14]) {
                         $societe->code_fournisseur = $ligne[14];
                     }
                     /*if ($ligne[15]) $societe->array_options["options_zone"]=$ligne[15];
                     				if (!empty($ligne[16])) $societe->array_options["options_CA"]=$ligne[16];
                     
                     				if (!empty($ligne[17]))
                     				{
                     					   if ($ligne[17] <= 5) $societe->effectif_id = 1;
                     					   elseif ($ligne[17] <= 10) $societe->effectif_id = 2;
                     					   elseif ($ligne[17] <= 50) $societe->effectif_id = 3;
                     					   elseif ($ligne[17] <= 100) $societe->effectif_id = 4;
                     					   elseif ($ligne[17] <= 500) $societe->effectif_id = 5;
                     					   else $societe->effectif_id = 7;
                     				}
                     				dol_syslog("effectif " . $lige[17].'  '.$societe->effectif_id." ".print_r($societe->array_options, true), LOG_DEBUG);*/
                     $this->db->begin;
                     switch ($typeimport) {
                         case 'C':
                             if ($sid > 0) {
                                 if ($societe->update($sid, $this->user) < 0) {
                                     $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error) . "\n";
                                     $error++;
                                 }
                             } elseif ($societe->create($this->user) < 0) {
                                 $this->process_msg .= $langs->trans("ErrCompanyCreate", $ligne[0], $societe->error) . "\n";
                                 $error++;
                             }
                             break;
                             /*case 'M':
                             		if ($sid>0) 
                             		{
                             			if ($societe->update($sid, $this->user) < 0){
                             				$this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n";
                             				$error++;
                             			}
                             		}
                             		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n";
                             		break;*/
                         /*case 'M':
                         		if ($sid>0) 
                         		{
                         			if ($societe->update($sid, $this->user) < 0){
                         				$this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n";
                         				$error++;
                         			}
                         		}
                         		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n";
                         		break;*/
                         case 'D':
                             if ($sid > 0) {
                                 if ($societe->delete($sid) < 0) {
                                     $this->process_msg .= $langs->trans("ErrCompanyDelete", $ligne[0], $societe->error) . "\n";
                                     $error++;
                                 }
                             } else {
                                 $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("CompanyNoExist", $ligne[0]) . "\n";
                             }
                     }
                     if (!$error) {
                         $this->db->commit();
                     } else {
                         $this->db->rollback();
                     }
                 }
                 break;
             case 'ImportContact':
                 $i = 0;
                 //$contact=new Contact($this->db);
                 //$societe = new Societe($this->db);
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $i++;
                     $contact = new Contact($this->db);
                     $societe = new Societe($this->db);
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n";
                     if ($ligne[0]) {
                         $socid = $this->get_socbyclientcode($ligne[0]);
                     } else {
                         if ($ligne[1]) {
                             $socid = $this->get_socbysuplliercode($ligne[1]);
                         }
                     }
                     if ($socid < 0) {
                         $this->process_msg .= $i . " " . $langs->trans("ErrCompanyRequired") . "\n";
                     } else {
                         $societe->fetch($socid);
                     }
                     if (!$societe->id) {
                         $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0] . " " . $ligne[1]) . "\n";
                         continue;
                     }
                     if (empty($ligne[2])) {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n";
                         continue;
                     }
                     $contactid = $this->get_contact_id($socid, $ligne[2], $ligne[3]);
                     $contact->id = $contactid;
                     $contact->civilite_id = $ligne[4];
                     $contact->lastname = $ligne[2];
                     $contact->firstname = $ligne[3];
                     if ($ligne[5] || $ligne[6] || $ligne[7]) {
                         $contact->address = $ligne[5] . "\n" . $ligne[6] . "\n" . $ligne[7];
                     } else {
                         $contact->address = $societe->address;
                     }
                     if ($ligne[8]) {
                         $contact->zip = $ligne[8];
                     } else {
                         $contact->zip = $societe->zip;
                     }
                     if ($ligne[9]) {
                         $contact->town = $ligne[9];
                     } else {
                         $contact->town = $societe->town;
                     }
                     if ($ligne[10]) {
                         $pid = dol_getIdFromCode($this->db, $ligne[10], "c_pays", "code", "rowid");
                         if ($pid <= 0) {
                             $pid = '';
                         }
                         $contact->country_id = $pid;
                         $contact->country_code = $ligne[10];
                     } else {
                         $contact->country_id = $societe->country_id;
                         $contact->country_code = $societe->country_code;
                     }
                     $contact->socid = $socid;
                     // fk_soc
                     $contact->status = 1;
                     $contact->email = $ligne[11];
                     $contact->phone_pro = $ligne[12];
                     $contact->fax = $ligne[13];
                     $contact->phone_mobile = $ligne[14];
                     $contact->priv = 0;
                     $this->db - begin;
                     switch ($typeimport) {
                         case 'C':
                             if ($contactid > 0) {
                                 if ($contact->update($contactid, $this->user) < 0) {
                                     $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error) . "\n";
                                     $error++;
                                 }
                             } elseif ($contact->create($this->user) < 0) {
                                 $this->process_msg .= $langs->trans("ErrContactCreate", $ligne[2], $contact->error) . "\n";
                                 $error++;
                             }
                             break;
                             /*case 'M':
                             		if ($contactid>0) 
                             		{
                             			if ($contact->update($contactid, $this->user) < 0){
                             				$this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n";
                             				$error++;
                             			}
                             		}
                             		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n";
                             		break;*/
                         /*case 'M':
                         		if ($contactid>0) 
                         		{
                         			if ($contact->update($contactid, $this->user) < 0){
                         				$this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n";
                         				$error++;
                         			}
                         		}
                         		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n";
                         		break;*/
                         case 'D':
                             if ($contactid > 0) {
                                 if ($contact->delete($contactid) < 0) {
                                     $this->process_msg .= $langs->trans("ErrContactDelete", $ligne[2], $contact->error) . "\n";
                                     $error++;
                                 }
                             } else {
                                 $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ContactNoExist", $ligne[2]) . "\n";
                             }
                     }
                     if (!$error) {
                         $this->db->commit();
                     } else {
                         $this->db->rollback();
                     }
                 }
                 break;
                 /*case 'ImportActions':
                 			$i=0;
                 			$contact=new Contact($this->db);
                 			$societe = new Societe($this->db);
                 			$actioncomm = new ActionComm($this->db);
                 			$actuser = new User($this->db);
                 			
                 			while ($ligne = fgetcsv($fp,1000,";"))
                 			{
                 				$i++;
                 				if ($this->firstline && $i== 1) continue;
                 				
                 				//if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n";
                 				//else $socid = $societe->id;
                 				$socid = $this->get_socbyclientcode($ligne[0]);
                 				if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n";
                 				else $societe->fetch($socid);
                 				$socid = $societe->id;
                 				
                 				if (!$socid) 
                 				{
                 					$this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n";
                 					continue;
                 				}
                 								
                 				//action sur un contact de la soc
                 				if ($ligne[1])
                 				{
                 					$contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ;
                 					
                 					if ($contactid < 0) {
                 						$this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n";
                 						// réinitialiser ??
                 						continue;
                 					}
                 					else $contact->fetch($contactid);
                 					
                 				}
                 				
                 
                 				$usertodo = '';
                 				if ($ligne[9])
                 				{
                 					$usertodo=new User($this->db);
                 					if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n";
                 				}
                 				$userdone= '' ;
                 				if ($ligne[10])
                 				{
                 					$usertodo=new User($this->db);
                 					if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n";
                 					
                 				}
                 				$datep = '';
                 				if ($ligne[6])
                 				{
                 					// voir date
                 					$n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
                 					if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
                 					if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n";
                 				}
                 				else $datep ='';
                 				$datef='';
                 				if ($ligne[7])
                 				{
                 					// voir la date
                 					$n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
                 					if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
                 					if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n";
                 				}
                 				else $datef ='';
                 				//$datef='';
                 				$actioncomm->societe = $societe;
                 				if ($ligne[1]) $actioncomm->contact = $contact;
                 				else $actioncomm->contact = '';
                 				$actioncomm->type_code = $ligne[3];
                 				$actioncomm->priority = $ligne[4];
                 				$actioncomm->location = '' ;
                 				$actioncomm->label = $ligne[5];
                 				$actioncomm->datep = $datep;
                 				$actioncomm->datef = $datef;
                 				$actioncomm->percentage = $ligne[8];
                 				$actioncomm->usertodo = $usertodo;
                 				$actioncomm->userdone = $userdone;
                 				$actioncomm->note =$ligne[11];
                 				
                 				switch ($typeimport)
                 				{					
                 				case 'C':
                 					$this->db->begin();
                 					if ($actioncomm->add($this->user) < 0) 
                 					{ 
                 						$this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n";
                 						$this->db->rollback();
                 					}
                 					else $this->db->commit();
                 					break;
                 				case 'M':
                 					$this->db->begin();
                 					if($actioncomm->update($user) < 0){
                 						$this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n";
                 						$this->db->rollback();
                 					}
                 					else $this->db->commit();
                 					break;
                 				case 'D':
                 					$this->db->begin();
                 					if($actioncomm->delete() < 0){
                 						$this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n";
                 						$this->db->rollback();
                 					}
                 					else $this->db->commit();
                 					break;
                 				}
                 			}
                 				
                 			break;*/
             /*case 'ImportActions':
             			$i=0;
             			$contact=new Contact($this->db);
             			$societe = new Societe($this->db);
             			$actioncomm = new ActionComm($this->db);
             			$actuser = new User($this->db);
             			
             			while ($ligne = fgetcsv($fp,1000,";"))
             			{
             				$i++;
             				if ($this->firstline && $i== 1) continue;
             				
             				//if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n";
             				//else $socid = $societe->id;
             				$socid = $this->get_socbyclientcode($ligne[0]);
             				if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n";
             				else $societe->fetch($socid);
             				$socid = $societe->id;
             				
             				if (!$socid) 
             				{
             					$this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n";
             					continue;
             				}
             								
             				//action sur un contact de la soc
             				if ($ligne[1])
             				{
             					$contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ;
             					
             					if ($contactid < 0) {
             						$this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n";
             						// réinitialiser ??
             						continue;
             					}
             					else $contact->fetch($contactid);
             					
             				}
             				
             
             				$usertodo = '';
             				if ($ligne[9])
             				{
             					$usertodo=new User($this->db);
             					if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n";
             				}
             				$userdone= '' ;
             				if ($ligne[10])
             				{
             					$usertodo=new User($this->db);
             					if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n";
             					
             				}
             				$datep = '';
             				if ($ligne[6])
             				{
             					// voir date
             					$n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
             					if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
             					if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n";
             				}
             				else $datep ='';
             				$datef='';
             				if ($ligne[7])
             				{
             					// voir la date
             					$n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
             					if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
             					if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n";
             				}
             				else $datef ='';
             				//$datef='';
             				$actioncomm->societe = $societe;
             				if ($ligne[1]) $actioncomm->contact = $contact;
             				else $actioncomm->contact = '';
             				$actioncomm->type_code = $ligne[3];
             				$actioncomm->priority = $ligne[4];
             				$actioncomm->location = '' ;
             				$actioncomm->label = $ligne[5];
             				$actioncomm->datep = $datep;
             				$actioncomm->datef = $datef;
             				$actioncomm->percentage = $ligne[8];
             				$actioncomm->usertodo = $usertodo;
             				$actioncomm->userdone = $userdone;
             				$actioncomm->note =$ligne[11];
             				
             				switch ($typeimport)
             				{					
             				case 'C':
             					$this->db->begin();
             					if ($actioncomm->add($this->user) < 0) 
             					{ 
             						$this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n";
             						$this->db->rollback();
             					}
             					else $this->db->commit();
             					break;
             				case 'M':
             					$this->db->begin();
             					if($actioncomm->update($user) < 0){
             						$this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n";
             						$this->db->rollback();
             					}
             					else $this->db->commit();
             					break;
             				case 'D':
             					$this->db->begin();
             					if($actioncomm->delete() < 0){
             						$this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n";
             						$this->db->rollback();
             					}
             					else $this->db->commit();
             					break;
             				}
             			}
             				
             			break;*/
             case 'Importtarif':
                 // ref four
                 $i = 0;
                 $this->process_msg = '';
                 $error = 0;
                 /*$doliprod = new Product($this->db);
                 		$product = new ProductFournisseur($this->db);
                 		$societe = new Societe($this->db);*/
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $doliprod->id = '';
                     $i++;
                     $doliprod = new Product($this->db);
                     $product = new ProductFournisseur($this->db);
                     $societe = new Societe($this->db);
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     // recherche du fournisseur
                     if ($societe->fetch('', $ligne[2]) > 0) {
                         $sid = $societe->id;
                     } else {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrComppanyNoExist", $ligne[2]) . "\n";
                         $sid = '';
                     }
                     if ($doliprod->fetch('', $ligne[0]) > 0) {
                         $pid = $doliprod->id;
                     } else {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrProductNoExist", $ligne[0], $doliprod->error) . "\n";
                         $pid = '';
                     }
                     if ($sid > 0 && $pid > 0) {
                         $result = $product->fetch($doliprod->id);
                         if ($result > 0) {
                             $this->db->begin();
                             switch ($typeimport) {
                                 case 'C':
                                     $ret = $product->add_fournisseur($this->user, $sid, $ligne[1], $ligne[3]);
                                     if ($ret < 0 && $ret != -3) {
                                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n";
                                         $error++;
                                     }
                                     $ret = $product->update_buyprice($ligne[3], $ligne[4], $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5]);
                                     if ($ret < 0 && $ret != -3) {
                                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n";
                                         $error++;
                                     }
                                     break;
                                     /*case 'M':
                                     		{
                                     			// gestion du prix obligatoire
                                     			$supplier=new Fournisseur($this->db);
                                     			$result=$supplier->fetch($sid);
                                     			
                                     			$ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] );
                                     			if ($ret < 0)
                                     			{
                                     				$this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n";
                                     				$error ++;
                                     			}
                                     			
                                     		}
                                     		break;*/
                                 /*case 'M':
                                 		{
                                 			// gestion du prix obligatoire
                                 			$supplier=new Fournisseur($this->db);
                                 			$result=$supplier->fetch($sid);
                                 			
                                 			$ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] );
                                 			if ($ret < 0)
                                 			{
                                 				$this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n";
                                 				$error ++;
                                 			}
                                 			
                                 		}
                                 		break;*/
                                 case 'D':
                                     // suprresion de la ligne avec le même nb d'article et le même prix
                                     $sql = "SELECT pfp.rowid FROM " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp";
                                     $sql .= " WHERE pfp.quantity = '" . $ligne[3] . "' AND pfp.ref_fourn = '" . $ligne[1];
                                     $sql .= "' AND pfp.fk_soc = '" . $sid . "' AND pfp.fk_product='" . $pid . "'";
                                     $sql .= " AND pfp.entity = " . $conf->entity;
                                     $resql = $this->db->query($sql);
                                     if ($resql) {
                                         $obj = $this->db->fetch_object($resql);
                                         if ($obj->rowid > 0) {
                                             $result = $product->remove_product_fournisseur_price($obj->rowid);
                                         } else {
                                             $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrDeletePrice", $product->error) . "\n";
                                             $error++;
                                         }
                                     } else {
                                         $this->process_msg .= "Error SQL= " . $sql . "\n";
                                         $error++;
                                     }
                                     break;
                             }
                             //switch
                         }
                         if (!$error) {
                             $this->db->commit();
                         } else {
                             $this->db->rollback();
                         }
                     }
                     // fournisseur trouvé
                 }
                 // traitement ligne
                 // while reffour
                 break;
         }
         // fin switch
         fclose($fp);
     } else {
         $this->error = $langs->trans("ErrOpenFile") . $nomfich;
         $error = -1;
     }
     return $error;
 }
Ejemplo n.º 10
0
 /**
  * testContactUpdate
  *
  * @param	Contact		$localobject	Contact
  * @return	int
  *
  * @depends	testContactFetch
  * The depends says test is run only if previous is ok
  */
 public function testContactUpdate($localobject)
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject->oldcopy = clone $localobject;
     $localobject->note_private = 'New private note after update';
     $localobject->note_public = 'New public note after update';
     $localobject->lastname = 'New name';
     $localobject->firstname = 'New firstname';
     $localobject->address = 'New address';
     $localobject->zip = 'New zip';
     $localobject->town = 'New town';
     $localobject->country_id = 2;
     //$localobject->status=0;
     $localobject->phone_pro = 'New tel pro';
     $localobject->phone_perso = 'New tel perso';
     $localobject->phone_mobile = 'New tel mobile';
     $localobject->fax = 'New fax';
     $localobject->email = '*****@*****.**';
     $localobject->jabberid = 'New im id';
     $localobject->default_lang = 'es_ES';
     $result = $localobject->update($localobject->id, $user);
     print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0, 'Contact::update error');
     $result = $localobject->update_note($localobject->note_private, '_private');
     print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0, 'Contact::update_note (private) error');
     $result = $localobject->update_note($localobject->note_public, '_public');
     print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0, 'Contact::update_note (public) error');
     $newobject = new Contact($this->savdb);
     $result = $newobject->fetch($localobject->id);
     print __METHOD__ . " id=" . $localobject->id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0, 'Contact::fetch error');
     print __METHOD__ . " old=" . $localobject->note_private . " new=" . $newobject->note_private . "\n";
     $this->assertEquals($localobject->note_private, $newobject->note_private);
     //print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n";
     //$this->assertEquals($localobject->note_public, $newobject->note_public);
     print __METHOD__ . " old=" . $localobject->lastname . " new=" . $newobject->lastname . "\n";
     $this->assertEquals($localobject->lastname, $newobject->lastname);
     print __METHOD__ . " old=" . $localobject->firstname . " new=" . $newobject->firstname . "\n";
     $this->assertEquals($localobject->firstname, $newobject->firstname);
     print __METHOD__ . " old=" . $localobject->address . " new=" . $newobject->address . "\n";
     $this->assertEquals($localobject->address, $newobject->address);
     print __METHOD__ . " old=" . $localobject->zip . " new=" . $newobject->zip . "\n";
     $this->assertEquals($localobject->zip, $newobject->zip);
     print __METHOD__ . " old=" . $localobject->town . " new=" . $newobject->town . "\n";
     $this->assertEquals($localobject->town, $newobject->town);
     print __METHOD__ . " old=" . $localobject->country_id . " new=" . $newobject->country_id . "\n";
     $this->assertEquals($localobject->country_id, $newobject->country_id);
     print __METHOD__ . " old=BE new=" . $newobject->country_code . "\n";
     $this->assertEquals('BE', $newobject->country_code);
     //print __METHOD__." old=".$localobject->status." new=".$newobject->status."\n";
     //$this->assertEquals($localobject->status, $newobject->status);
     print __METHOD__ . " old=" . $localobject->phone_pro . " new=" . $newobject->phone_pro . "\n";
     $this->assertEquals($localobject->phone_pro, $newobject->phone_pro);
     print __METHOD__ . " old=" . $localobject->phone_pro . " new=" . $newobject->phone_pro . "\n";
     $this->assertEquals($localobject->phone_perso, $newobject->phone_perso);
     print __METHOD__ . " old=" . $localobject->phone_mobile . " new=" . $newobject->phone_mobile . "\n";
     $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile);
     print __METHOD__ . " old=" . $localobject->fax . " new=" . $newobject->fax . "\n";
     $this->assertEquals($localobject->fax, $newobject->fax);
     print __METHOD__ . " old=" . $localobject->email . " new=" . $newobject->email . "\n";
     $this->assertEquals($localobject->email, $newobject->email);
     print __METHOD__ . " old=" . $localobject->jabberid . " new=" . $newobject->jabberid . "\n";
     $this->assertEquals($localobject->jabberid, $newobject->jabberid);
     print __METHOD__ . " old=" . $localobject->default_lang . " new=" . $newobject->default_lang . "\n";
     $this->assertEquals($localobject->default_lang, $newobject->default_lang);
     return $localobject;
 }
Ejemplo n.º 11
0
 /**
  * saveWebForm()
  * this will check if contact exists with firname, lastname, name and email 
  * If exist add to it, if doesn't exists create a new one.
  */
 function posteventAddContact($fid, $fields, $nxturl, $uid, $tags)
 {
     //echo 'hh';die();
     //$fields = $_REQUEST['fields'];
     //$fields = $event_controler->fields;
     $this->setLog("\n eventAddContact, creating new contact from form, using " . count($fields) . " fields. (" . date("Y/m/d H:i:s") . ")");
     //$dropcode = $_POST['dropcode'];
     $do_contact = new Contact();
     $do_contact->iduser = $uid;
     $do_contact->add();
     $this->setLog("\n new contact:" . $do_contact->idcontact . " for user:"******"\n Processing field:" . $field_name . " with value:" . $field_value);
         $do_webform_fields = new WebFormUserField();
         $do_webform_fields->query("SELECT wfu.name, wff.class as class_name, wff.variable, wff.variable_type, wfu.required \n\t\t                                   FROM webformfields as wff, webformuserfield as wfu \n\t\t\t\t\t\t\t\t\t\t   WHERE wff.name=wfu.name\n\t\t\t\t\t\t\t\t\t\t     AND wfu.name = '" . $field_name . "'\n\t\t\t\t\t\t\t\t\t\t\t AND wfu.idwebformuser= "******"\n Field information class:" . $do_webform_fields->class_name . " Variable:" . $do_webform_fields->variable);
         $this->setLog("\n rows:" . $do_webform_fields->getNumRows());
         if ($do_webform_fields->getNumRows() == 1) {
             if ($do_webform_fields->class_name == "Contact") {
                 $this->setLog("\n     Updating contact");
                 $do_contact->{$do_webform_fields->variable} = $field_value;
                 $do_contact->update();
             } else {
                 $update = false;
                 if (is_object(${'sub_' . $do_webform_fields->class_name})) {
                     if (${'sub_' . $do_webform_fields->class_name}->getType() == $do_webform_fields->variable_type) {
                         $update = true;
                     }
                 }
                 if ($update) {
                     $this->setLog("\n     Updating class:" . $do_webform_fields->class_name);
                     $obj = ${'sub_' . $do_webform_fields->class_name};
                     $obj->{$do_webform_fields->variable} = $field_value;
                     $obj->update();
                 } else {
                     $class_name = $do_webform_fields->class_name;
                     ${'sub_' . $class_name} = new $class_name();
                     $obj = ${'sub_' . $class_name};
                     $obj->{$do_webform_fields->variable} = $field_value;
                     if (method_exists($obj, "setType") && strlen($do_webform_fields->variable_type) > 0) {
                         $obj->setType($do_webform_fields->variable_type);
                     }
                     $obj->idcontact = $do_contact->getPrimaryKeyValue();
                     $obj->add();
                 }
             }
         }
     }
     $contact_view = new ContactView();
     $contact_view->setUser($uid);
     $contact_view->addFromContact($do_contact);
     $tags = explode(",", $tags);
     foreach ($tags as $tag) {
         $tag = trim($tag);
         $do_tag = new Tag();
         $do_tag->addNew();
         $do_tag->addTagAssociation($do_contact->getPrimaryKeyValue(), $tag, "contact", $fid);
         $contact_view->addTag($tag);
     }
     if (strlen($nexturl) > 0) {
         //$event_controler->setUrlNext($this->urlnext);
         header("location:{$nxturl}");
     } else {
         //$event_controler->setUrlNext($GLOBALS['cfg_ofuz_site_http_base'].'web_form_thankyou.php');
         $url = $GLOBALS['cfg_ofuz_site_http_base'] . 'web_form_thankyou.php';
         header("location:{$url}");
     }
     //$event_controler->addParam("do_contact", $do_contact);
 }
Ejemplo n.º 12
0
 /**
  * Updates a contact entry in ofuz Database.
  * @param array,int,int : contact details, contact id, company id
  * @return void
  * @see class : Company, Contact
  */
 function updateContactEntry($entry, $id_contact, $id_company = null)
 {
     if (!$id_company) {
         $new_company = new Company();
         $new_company->name = $entry['org_name'];
         $new_company->iduser = $this->id_user;
         $new_company->add();
         $id_company = $new_company->getPrimaryKeyValue();
     }
     $contact = new Contact();
     $contact->getId($id_contact);
     // Primarykey id of the record to update
     $contact->company = $entry['org_name'];
     //do not update name while importing since Gmail has only one text box for the name
     //$contact->firstname = $entry['title'];
     $contact->idcompany = $id_company;
     //$contact->iduser = $this->id_user;
     $contact->position = $entry['org_title'];
     $contact->update();
     $q_contact = new sqlQuery($this->getDbCon());
     $sql_sel = "SELECT * FROM contact_address WHERE idcontact = " . $id_contact;
     $q_contact->query($sql_sel);
     if ($q_contact->getNumRows()) {
         while ($q_contact->fetch()) {
             if ($q_contact->getData("address_type") == "Home") {
                 $contact->updateAddress($entry['address_home'], 'Home', $q_contact->getData("idcontact_address"));
             }
             if ($q_contact->getData("address_type") == "Other") {
                 $contact->updateAddress($entry['address_other'], 'Other', $q_contact->getData("idcontact_address"));
             }
             if ($q_contact->getData("address_type") == "Work") {
                 $contact->updateAddress($entry['address_work'], 'Work', $q_contact->getData("idcontact_address"));
             }
         }
     }
     $sql_sel = "SELECT * FROM contact_email WHERE idcontact = " . $id_contact;
     $q_contact->query($sql_sel);
     if ($q_contact->getNumRows()) {
         while ($q_contact->fetch()) {
             if ($q_contact->getData("email_type") == "Home") {
                 $contact->updateEmail($entry['em_home'], 'Home', $q_contact->getData("idcontact_email"));
             }
             if ($q_contact->getData("email_type") == "Other") {
                 $contact->updateEmail($entry['em_other'], 'Other', $q_contact->getData("idcontact_email"));
             }
             if ($q_contact->getData("email_type") == "Work") {
                 $contact->updateEmail($entry['em_work'], 'Work', $q_contact->getData("idcontact_email"));
             }
         }
     }
     $sql_sel = "SELECT * FROM contact_phone WHERE idcontact = " . $id_contact;
     $q_contact->query($sql_sel);
     if ($q_contact->getNumRows()) {
         while ($q_contact->fetch()) {
             if ($q_contact->getData("phone_type") == "Home") {
                 $contact->updatePhone($entry['ph_home'], 'Home', $q_contact->getData("idcontact_phone"));
             }
             if ($q_contact->getData("phone_type") == "Mobile") {
                 $contact->updatePhone($entry['ph_mobile'], 'Mobile', $q_contact->getData("idcontact_phone"));
             }
             if ($q_contact->getData("phone_type") == "Work") {
                 $contact->updatePhone($entry['ph_work'], 'Work', $q_contact->getData("idcontact_phone"));
             }
         }
     }
 }
Ejemplo n.º 13
0
	public function updateContact($mysql, $cid, $name, $email, $phone, $ownerid) {
		$con = new Contact();
			switch($con->select($cid, $ownerid, $mysql)) {
				case Contact::DATABASE_ERROR :
				{
					echo "<p>A Database error has occured.</p>";
					return;
				}
				case Contact::INVALID_DATA :
				{
					echo "<p>Invalid operation requested.</p>";
					return;
				}
				case Contact::SELECT_SUCCESS : 
				default :
					break;
			}
			
			$con->read($ownerid, $name, $email, $phone);
			
			switch($con->update($mysql)) {
				case Contact::DATABASE_ERROR :
				{
					echo "<p>A Database error has occured.</p>";
					return;
				}
				case Contact::INVALID_DATA :
				{
					echo "<p>Invalid operation requested.</p>";
					return;
				}
				case Contact::UPDATE_SUCCESS : 
				{
					echo "<p>Contact updated successfully.</p>";
					break;
				}
				default :
					break;
			}
	}
Ejemplo n.º 14
0
<?php

if (Tools::P('content')) {
    $contact = new Contact();
    $contact->copyFromPost();
    if ($contact->add()) {
        $c = new Contact(Tools::getRequest('id_parent'));
        $c->active = 1;
        $c->update();
        $vars = array('{name}' => $cookie->name, '{subject}' => $contact->subject, '{message}' => $contact->content);
        Mail::Send('replay', $c->subject, $vars, $c->email);
        if ($c->id_user > 0) {
            Alert::Send($c->id_user, $contact->content);
        }
    }
    if (is_array($contact->_errors) and count($contact->_errors) > 0) {
        $errors = $contact->_errors;
    } else {
        echo '<div class="conf">回复成功</div>';
    }
}
if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $obj = new Contact($id);
    $subs = $obj->getSubMessage();
    if ($obj->id_user > 0) {
        $userAllContact = $obj->getContactByUser();
    }
}
if (isset($errors)) {
    UIAdminAlerts::MError($errors);
Ejemplo n.º 15
0
        ?>
">Cancel</a>
				</span>
			</div>
		</div>

		<?php 
        //Validates data
        if (Input::exists()) {
            $validate = new Validation();
            $validation = $validate->check($_POST, array('band' => array('max' => 64), 'first_name' => array('max' => 64), 'last_name' => array('max' => 64), 'email' => array('required' => true, 'max' => 1024, 'is_email' => true), 'phone' => array('max' => 64, 'is_numeric' => true), 'mobile' => array('max' => 64, 'is_numeric' => true), 'company' => array('max' => 64), 'add_line_1' => array('max' => 128), 'add_line_2' => array('max' => 128), 'state' => array('max' => 128), 'city' => array('max' => 128), 'post_code' => array('max' => 128, 'is_numeric' => true)));
            if ($validation->passed()) {
                $contact = new Contact();
                try {
                    //sends updated data to the database
                    $contact->update(Input::get('id'), array('company' => Input::get('company'), 'band' => Input::get('band'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'add_line_1' => Input::get('add_line_1'), 'add_line_2' => Input::get('add_line_2'), 'state' => Input::get('state'), 'city' => Input::get('city'), 'post_code' => Input::get('post_code'), 'phone' => Input::get('phone'), 'mobile' => Input::get('mobile'), 'notes' => Input::get('notes'), 'date_modified' => date('Y-m-d H:i:s')));
                    Session::flash('home', 'The <a href="contact.php?id=' . Input::get('id') . '">contact</a> has been updated successfully');
                    Redirect::to('index.php');
                } catch (Exception $e) {
                    Session::flash('home', $e->getMessage());
                    Redirect::to('index.php');
                    exit;
                }
            } else {
                echo '<ul class="error">';
                foreach ($validation->errors() as $error) {
                    echo '<li>' . $error . '</li>';
                }
                echo '</ul>';
            }
        }
Ejemplo n.º 16
0
 function updatecontract($_post)
 {
     $profile = new Contact($this->getUser()->id);
     return $profile->update($_post);
 }
Ejemplo n.º 17
0
 /**
  * Import a Twitter friend
  */
 function importTwitterFriend($friend_data, $extra_tag = '')
 {
     $iduser = $_SESSION['do_User']->iduser;
     $tw_user_id = $friend_data['user_id'];
     $idcontact = $this->isTwFriendInContacts($iduser, $tw_user_id);
     list($fname, $lname) = explode(' ', $friend_data['name'], 2);
     $screen_name = $friend_data['screen_name'];
     $description = $friend_data['description'];
     $profile_image_url = $friend_data['profile_image_url'];
     $url = $friend_data['url'];
     $do_tag = new Tag();
     if ($idcontact) {
         //update the data
         $c = new Contact();
         $c->getId($idcontact);
         $c->firstname = $fname;
         $c->lastname = $lname;
         if ($c->picture == "") {
             $c->picture = $profile_image_url;
         }
         $c->tw_user_id = $tw_user_id;
         $c->update();
         $do_tag->addTagAssociation($idcontact, 'Twitter', 'contact', $iduser);
         if ($extra_tag != '') {
             $do_tag->addTagAssociation($idcontact, $extra_tag, 'contact', $iduser);
         }
     } else {
         // new entry
         $c = new Contact();
         $c->firstname = $fname;
         $c->lastname = $lname;
         $c->iduser = $iduser;
         $c->picture = $profile_image_url;
         $c->tw_user_id = $tw_user_id;
         $c->add();
         $idcontact = $c->idcontact;
         $w = new ContactWebsite();
         $w->idcontact = $idcontact;
         $w->website = 'http://twitter.com/' . $screen_name;
         $w->website_type = 'Twitter';
         $w->feed_auto_fetch = 'Yes';
         $w->add();
         if ($url != '') {
             $w = new ContactWebsite();
             $w->idcontact = $idcontact;
             $w->website = $url;
             $w->website_type = 'Personal';
             $w->add();
         }
         $link = '<br /><a href="http://twitter.com/' . $screen_name . '" target="_blank">Back to the Source of the Article</a><br />';
         $do_contact_note = new ContactNotes();
         $do_contact_note->idcontact = $idcontact;
         $do_contact_note->note = $description . $link;
         $do_contact_note->date_added = date('Y-m-d');
         $do_contact_note->iduser = $iduser;
         $do_contact_note->add();
         $do_tag->addTagAssociation($idcontact, 'Twitter', 'contact', $iduser);
         if ($extra_tag != '') {
             $do_tag->addTagAssociation($idcontact, $extra_tag, 'contact', $iduser);
         }
     }
 }
Ejemplo n.º 18
0
$_POST['id'] = $_POST['id'];
$_POST['userid'] = $_POST['userid'];
$_POST['type'] = $_POST['type'];
$_POST['type2'] = $_POST['type2'];
$con = new Contact();
for ($i = 0; $i < count($_POST['type']); $i++) {
    // $type[] = '("' . $_POST['type'][$i] . '")';
    // $type2[] = '("' . $_POST['type2'][$i]['value'] . ','. '")';
    $values[] = '("' . $_POST['userid'] . '","' . $_POST['type'][$i] . '","' . $_POST['type2'][$i]['value'] . '")';
    // $values[] = '('.$_POST['userid'].',"' . $_POST['type'][$i] . '","' . $_POST['type2'][$i]['value'] . '")';
    //ito lahat
    $data_con[] = $con->get_contact($_POST['id'][$i]);
    if ($data_con[$i]->type != $_POST['type'][$i]) {
        $id = $_POST['id'][$i];
        $datatype = $_POST['type'][$i];
        $data[] = $con->update($id, $datatype);
    }
    if ($data_con[$i]->type2 != $_POST['type2'][$i]) {
        $id = $_POST['id'][$i];
        $datatype2 = $_POST['type2'][$i]['value'];
        $data[] = $con->updatetype($id, $datatype2);
    }
    if ($_POST['type'][$i] == "" || empty($_POST['type'][$i])) {
        $data[] = $con->unlink($_POST['id'][$i]);
        $_POST['id'][$i] = "";
        unset($_POST);
    }
    //end
    if ($_POST['id'][$i] == "") {
        $sql = "INSERT INTO a_contact(userid,type,type2) VALUES ({$_POST['userid']},'{$_POST['type'][$i]}','{$_POST['type2'][$i]['value']}')";
        $con->createim($sql);