Beispiel #1
0
 public function postContact()
 {
     global $smarty, $cookie;
     session_start();
     if ($_SESSION['validate_code'] == strtolower(Tools::getRequest('validate_code'))) {
         if ($cookie->isLogged()) {
             $user = new User($cookie->id_user);
             $_POST['name'] = $user->first_name . ' ' . $user->last_name;
             $_POST['email'] = $user->email;
             if (isset($_POST['id_user'])) {
                 unset($_POST['id_user']);
             }
             $_POST['id_user'] = $user->id;
         }
         $contact = new Contact();
         $contact->copyFromPost();
         if ($contact->add()) {
             $vars = array('{name}' => $contact->name, '{subject}' => $contact->subject, '{email}' => $contact->email, '{message}' => $contact->content);
             Mail::Send('contact', $contact->subject, $vars, Configuration::get('TM_SHOP_EMAIL'));
             $this->_success = 'Your message has been successfully sent to our team.';
         } else {
             $this->_errors = $contact->_errors;
         }
     } else {
         $this->_errors[] = 'Confirmation code is error!';
     }
 }
 function eventGetContacts(EventControler $evtcl)
 {
     $plugType = 'email';
     $provider_box = $evtcl->provider_box;
     $email_box = $evtcl->email_box;
     $password_box = $evtcl->password_box;
     $msg = "";
     $contacts = "";
     $ok = false;
     if (empty($email_box)) {
         $msg = "Email missing !";
     }
     if (empty($password_box)) {
         $msg = "Password missing !";
     }
     if (empty($provider_box)) {
         $msg = "Provider missing !";
     }
     if ($msg == "") {
         $inviter = new OpenInviter();
         $inviter->startPlugin($provider_box);
         $internal = $inviter->getInternalError();
         if ($internal) {
             $msg = $internal;
         } elseif (!$inviter->login($email_box, $password_box)) {
             $internal = $inviter->getInternalError();
             $msg = $internal ? $internal : "Login failed. Please check the email and password you have provided and try again later !";
         } elseif (false === ($contacts = $inviter->getMyContacts())) {
             $msg = "Unable to get contacts !";
         } else {
             $msg = "Contacts imported successfully.";
             $ok = true;
             //$_POST['oi_session_id']=$inviter->plugin->getSessionID();
         }
     }
     if ($ok) {
         /*print_r($contacts);
         		exit();*/
         foreach ($contacts as $email => $name) {
             $do_contact = new Contact();
             $do_contact->firstname = $name;
             $do_contact->iduser = $_SESSION['do_User']->iduser;
             $do_contact->add();
             $lastInsertedContId = $do_contact->getPrimaryKeyValue();
             $do_contact->addEmail($email, 'Home');
             $do_contact->free();
             //contact view
             $do_cv = new ContactView();
             $do_cv->idcontact = $lastInsertedContId;
             $do_cv->firstname = $name;
             $do_cv->email_address = $email;
             $do_cv->add();
             $do_cv->free();
         }
     }
     $_SESSION['in_page_message'] = $msg;
 }
 public function contactAction()
 {
     $data = $this->data;
     if ($this->getProductsData()) {
         $input = $this->getProductsData();
         $captcha = md5($input['captcha']);
         if ($captcha == $this->app['session']->get('captcha_hash', 'null')) {
             $getData = array('name' => strip_tags($input['txtName']), 'address' => strip_tags($input['txtAdd']), 'phone' => $input['txtPhone'], 'email' => strip_tags($input['txtEmail']), 'title' => strip_tags($input['txtTitle']), 'content' => $input['txtContent'], 'status' => '1');
             if (Contact::add($getData) == true) {
                 $this->app['session']->getFlashBag()->add('message', 'Success');
                 return $this->redirect('contact');
             } else {
                 $data['notification'] = 'Erro';
             }
         } else {
             $data['notification'] = 'Erro';
         }
     }
     //var_dump($data['lang']);die();
     return $this->render('default/Products/contact.html.twig', $data);
 }
Beispiel #4
0
 /**
  * Check right on CommonDBRelation object
  */
 public function testContact_Supplier()
 {
     global $DB;
     $DB->connect();
     $ent0 = $this->sharedFixture['entity'][0];
     $ent1 = $this->sharedFixture['entity'][1];
     $ent2 = $this->sharedFixture['entity'][2];
     // Super admin
     Session::changeProfile(4);
     $this->assertEquals(4, $_SESSION['glpiactiveprofile']['id']);
     $this->assertEquals(31, $_SESSION['glpiactiveprofile']['contact_enterprise']);
     // See all
     $this->assertTrue(Session::changeActiveEntities("all"));
     // Create some contacts
     $contact = new Contact();
     $idc[0] = $contact->add(array('name' => "Contact 1", 'entities_id' => $ent0, 'is_recursive' => 0));
     $this->assertGreaterThan(0, $idc[0]);
     $idc[1] = $contact->add(array('name' => "Contact 2", 'entities_id' => $ent0, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $idc[1]);
     $idc[2] = $contact->add(array('name' => "Contact 3", 'entities_id' => $ent1, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $idc[2]);
     $idc[3] = $contact->add(array('name' => "Contact 4", 'entities_id' => $ent2));
     $this->assertGreaterThan(0, $idc[3]);
     // Create some suppliers
     $supplier = new Supplier();
     $ids[0] = $supplier->add(array('name' => "Supplier 1", 'entities_id' => $ent0, 'is_recursive' => 0));
     $this->assertGreaterThan(0, $ids[0]);
     $ids[1] = $supplier->add(array('name' => "Supplier 2", 'entities_id' => $ent0, 'is_recursive' => 1));
     $this->assertGreaterThan(0, $ids[1]);
     $ids[2] = $supplier->add(array('name' => "Supplier 3", 'entities_id' => $ent1));
     $this->assertGreaterThan(0, $ids[2]);
     $ids[3] = $supplier->add(array('name' => "Supplier 4", 'entities_id' => $ent2));
     $this->assertGreaterThan(0, $ids[3]);
     // Relation
     $rel = new Contact_Supplier();
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[0]);
     // root
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[0] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[0]);
     $this->assertTrue($rel->can($idr[0], READ));
     $this->assertTrue($rel->canEdit($idr[0]));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[1] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[1]);
     $this->assertTrue($rel->can($idr[1], READ));
     $this->assertTrue($rel->canEdit($idr[1]));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[2]);
     // child 1
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[3]);
     // child 2
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[0]);
     // root
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[2] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[2]);
     $this->assertTrue($rel->can($idr[2], READ));
     $this->assertTrue($rel->canEdit($idr[2]));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[3] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[3]);
     $this->assertTrue($rel->can($idr[3], READ));
     $this->assertTrue($rel->canEdit($idr[3]));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[2]);
     // child 1
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[4] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[4]);
     $this->assertTrue($rel->can($idr[4], READ));
     $this->assertTrue($rel->canEdit($idr[4]));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[3]);
     // child 2
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[5] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[5]);
     $this->assertTrue($rel->can($idr[5], READ));
     $this->assertTrue($rel->canEdit($idr[5]));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[6] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[6]);
     $this->assertTrue($rel->can($idr[6], READ));
     $this->assertTrue($rel->canEdit($idr[6]));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[2]);
     // Child 1
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[7] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[7]);
     $this->assertTrue($rel->can($idr[7], READ));
     $this->assertTrue($rel->canEdit($idr[7]));
     $input = array('contacts_id' => $idc[2], 'suppliers_id' => $ids[3]);
     // Child 2
     $this->assertFalse($rel->can(-1, CREATE, $input));
     // See only in child entity 2 + parent if recursive
     $this->assertTrue(Session::changeActiveEntities($ent2));
     $this->assertFalse($rel->can($idr[0], READ));
     // root / root
     $this->assertFalse($rel->canEdit($idr[0]));
     $this->assertFalse($rel->can($idr[1], READ));
     // root / root rec
     $this->assertFalse($rel->canEdit($idr[1]));
     $this->assertFalse($rel->can($idr[2], READ));
     // root rec / root
     $this->assertFalse($rel->canEdit($idr[2]));
     $this->assertTrue($rel->can($idr[3], READ));
     // root rec / root rec
     $this->assertFalse($rel->canEdit($idr[3]));
     $this->assertFalse($rel->can($idr[4], READ));
     // root rec / child 1
     $this->assertFalse($rel->canEdit($idr[4]));
     $this->assertTrue($rel->can($idr[5], READ));
     // root rec / child 2
     $this->assertTrue($rel->canEdit($idr[5]));
     $this->assertFalse($rel->can($idr[6], READ));
     // child 1 / root rec
     $this->assertFalse($rel->canEdit($idr[6]));
     $this->assertFalse($rel->can($idr[7], READ));
     // child 1 / child 1
     $this->assertFalse($rel->canEdit($idr[7]));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[0], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[1], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[0]);
     // root
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[1]);
     // root + rec
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[7] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[7]);
     $this->assertTrue($rel->can($idr[7], READ));
     $this->assertTrue($rel->canEdit($idr[7]));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[2]);
     // Child 1
     $this->assertFalse($rel->can(-1, CREATE, $input));
     $input = array('contacts_id' => $idc[3], 'suppliers_id' => $ids[3]);
     // Child 3
     $this->assertTrue($rel->can(-1, CREATE, $input));
     $idr[8] = $rel->add($input);
     $this->assertGreaterThan(0, $idr[8]);
     $this->assertTrue($rel->can($idr[8], READ));
     $this->assertTrue($rel->canEdit($idr[8]));
 }
Beispiel #5
0
            </div>-->
        </div><br />

<?php 
$do_contact = new Contact();
$do_np_contact = new Contact();
if (!empty($_SESSION['do_User']->idcontact) && $_SESSION['do_User']->idcontact != 0) {
    $idcontact = $_SESSION['do_User']->idcontact;
    $do_contact->getId($_SESSION['do_User']->idcontact);
} else {
    // Add a new contact and update the idcontact to the user table for the user
    $do_contact->addNew();
    $do_contact->firstname = $_SESSION['do_User']->firstname;
    $do_contact->lastname = $_SESSION['do_User']->lastname;
    $do_contact->iduser = $_SESSION['do_User']->iduser;
    $do_contact->add();
    $idcontact_inserted = $do_contact->getPrimaryKeyValue();
    $do_contact_view = new ContactView();
    $_SESSION['do_User']->idcontact = $idcontact_inserted;
    $do_contact->getId($idcontact_inserted);
}
$_SESSION['edit_from_page'] = 'settings_myinfo.php';
$do_contact->sessionPersistent("ContactEditSave", "contact.php", OFUZ_TTL);
//$do_contact->sessionPersistent("ContactEditSave", "index.php", 120);
//$do_np_contact->sessionPersistent("ContactPictureSave", "index.php", 120);
$do_np_contact->sessionPersistent("ContactPictureSave", "index.php", OFUZ_TTL);
$_SESSION['ContactPictureSave']->getId($idcontact);
$e_fullContact = new Event("ContactPictureSave->eventValuesFromForm");
$e_fullContact->setLevel(1999);
$e_fullContact->setGotFile(true);
$e_fullContact->addEventAction("ContactPictureSave->update", 2000);
 function eventImportContactsFromCsv(EventControler $eventcontroler)
 {
     $iduser = $eventcontroler->iduser;
     $handle = fopen($eventcontroler->targetpath, "r");
     $row = 1;
     while ($data = fgetcsv($handle)) {
         $contact_firstname = "";
         $contact_lastname = "";
         $contact_company = "";
         $company = "";
         $contact_position = "";
         $contact_summary = "";
         $contact_birthday = "";
         $contact_city = "";
         $contact_state = "";
         $contact_street = "";
         $contact_zipcode = "";
         $contact_country = "";
         $contact_address_hm = "";
         $contact_address_hm_type = "";
         $contact_address_wk = "";
         $contact_address_wk_type = "";
         $contact_address_ot = "";
         $contact_address_ot_type = "";
         $contact_email_hm = "";
         $contact_email_hm_type = "";
         $contact_email_wk = "";
         $contact_email_wk_type = "";
         $contact_email_ot = "";
         $contact_email_ot_type = "";
         $contact_phone_hm = "";
         $contact_phone_hm_type = "";
         $contact_phone_wk = "";
         $contact_phone_wk_type = "";
         $contact_phone_ot = "";
         $contact_phone_ot_type = "";
         $contact_phone_mb = "";
         $contact_phone_mb_type = "";
         $contact_phone_fx = "";
         $contact_phone_fx_type = "";
         $contact_website_comp = "";
         $contact_website_comp_type = "";
         $contact_website_blog = "";
         $contact_website_blog_type = "";
         $contact_website_ot = "";
         $contact_website_ot_type = "";
         $contact_website_personal = "";
         $contact_website_personal_type = "";
         $contact_website_twitter = "";
         $contact_website_twitter_type = "";
         $contact_im_aim_wk = "";
         $contact_im_aim_wk_type = "";
         $contact_im_aim_per = "";
         $contact_im_aim_per_type = "";
         $contact_im_aim_ot = "";
         $contact_im_aim_ot_type = "";
         $im_aim = "";
         $contact_im_msn_wk = "";
         $contact_im_msn_wk_type = "";
         $contact_im_msn_per = "";
         $contact_im_msn_per_type = "";
         $contact_im_msn_ot = "";
         $contact_im_msn_ot_type = "";
         $im_msn = "";
         $contact_im_icq_wk = "";
         $contact_im_icq_wk_type = "";
         $contact_im_icq_per = "";
         $contact_im_icq_per_type = "";
         $contact_im_icq_ot = "";
         $contact_im_icq_ot_type = "";
         $im_icq = "";
         $contact_im_jabber_wk = "";
         $contact_im_jabber_wk_type = "";
         $contact_im_jabber_per = "";
         $contact_im_jabber_per_type = "";
         $contact_im_jabber_ot = "";
         $contact_im_jabber_ot_type = "";
         $im_jabber = "";
         $contact_im_yahoo_wk = "";
         $contact_im_yahoo_wk_type = "";
         $contact_im_yahoo_per = "";
         $contact_im_yahoo_per_type = "";
         $contact_im_yahoo_ot = "";
         $contact_im_yahoo_ot_type = "";
         $im_yahoo = "";
         $contact_im_skype_wk = "";
         $contact_im_skype_wk_type = "";
         $contact_im_skype_per = "";
         $contact_im_skype_per_type = "";
         $contact_im_skype_ot = "";
         $contact_im_skype_ot_type = "";
         $im_skype = "";
         $contact_im_gt_wk = "";
         $contact_im_gt_wk_type = "";
         $contact_im_gt_per = "";
         $contact_im_gt_per_type = "";
         $contact_im_gt_ot = "";
         $contact_im_gt_ot_type = "";
         $im_gt = "";
         $contact_note = "";
         $do_contact = new Contact();
         $do_company = new Company();
         $do_contact_notes = new ContactNotes();
         $num = count($data);
         if ($row > 1) {
             for ($c = 0; $c < $num; $c++) {
                 switch ($eventcontroler->fields[$c]) {
                     case "firstname":
                         $contact_firstname = $data[$c];
                         break;
                     case "lastname":
                         $contact_lastname = $data[$c];
                         break;
                     case "company":
                         $company = $data[$c];
                         $contact_company = $data[$c];
                         break;
                     case "position":
                         $contact_position = $data[$c];
                         break;
                     case "summary":
                         $contact_summary = $data[$c];
                         break;
                     case "birthday":
                         $contact_birthday = $data[$c];
                         break;
                     case "city":
                         $contact_city = $data[$c];
                         break;
                     case "state":
                         $contact_state = $data[$c];
                         break;
                     case "street":
                         $contact_street = $data[$c];
                         break;
                     case "zipcode":
                         $contact_zipcode = $data[$c];
                         break;
                     case "country":
                         $contact_country = $data[$c];
                         break;
                     case "address_hm":
                         $contact_address_hm = $data[$c];
                         $contact_address_hm_type = "Home";
                         break;
                     case "address_wk":
                         $contact_address_wk = $data[$c];
                         $contact_address_wk_type = "Work";
                         break;
                     case "address_ot":
                         $contact_address_ot = $data[$c];
                         $contact_address_ot_type = "Other";
                         break;
                     case "email_hm":
                         $contact_email_hm = $data[$c];
                         $contact_email_hm_type = "Home";
                         break;
                     case "email_wk":
                         $contact_email_wk = $data[$c];
                         $contact_email_wk_type = "Work";
                         break;
                     case "email_ot":
                         $contact_email_ot = $data[$c];
                         $contact_email_ot_type = "Other";
                         break;
                     case "phone_number_hm":
                         $contact_phone_hm = $data[$c];
                         $contact_phone_hm_type = "Home";
                         break;
                     case "phone_number_wk":
                         $contact_phone_wk = $data[$c];
                         $contact_phone_wk_type = "Work";
                         break;
                     case "phone_number_ot":
                         $contact_phone_ot = $data[$c];
                         $contact_phone_ot_type = "Other";
                         break;
                     case "phone_number_mb":
                         $contact_phone_mb = $data[$c];
                         $contact_phone_mb_type = "Mobile";
                         break;
                     case "phone_number_fx":
                         $contact_phone_fx = $data[$c];
                         $contact_phone_fx_type = "Fax";
                         break;
                     case "website_comp":
                         $contact_website_comp = $data[$c];
                         $contact_website_comp_type = "Company";
                         break;
                     case "website_blog":
                         $contact_website_blog = $data[$c];
                         $contact_website_blog_type = "Blog";
                         break;
                     case "website_ot":
                         $contact_website_ot = $data[$c];
                         $contact_website_ot_type = "Other";
                         break;
                     case "website_personal":
                         $contact_website_personal = $data[$c];
                         $contact_website_personal_type = "Personal";
                         break;
                     case "website_twitter":
                         $contact_website_twitter = $data[$c];
                         $contact_website_twitter_type = "Twitter";
                         break;
                     case "website_linkedin":
                         $contact_website_linkedin = $data[$c];
                         $contact_website_linkedin_type = "LinkedIn";
                         break;
                     case "website_fb":
                         $contact_website_fb = $data[$c];
                         $contact_website_fb_type = "Facebook";
                         break;
                     case "im_aim_wk":
                         $contact_im_aim_wk = $data[$c];
                         $im_aim = "AIM";
                         $contact_im_aim_wk_type = "Work";
                         break;
                     case "im_aim_per":
                         $contact_im_aim_per = $data[$c];
                         $im_aim = "AIM";
                         $contact_im_aim_per_type = "Personal";
                         break;
                     case "im_aim_ot":
                         $contact_im_aim_ot = $data[$c];
                         $im_aim = "AIM";
                         $contact_im_aim_ot_type = "Other";
                         break;
                     case "im_msn_wk":
                         $contact_im_msn_wk = $data[$c];
                         $im_msn = "MSN";
                         $contact_im_msn_wk_type = "Work";
                         break;
                     case "im_msn_per":
                         $contact_im_msn_per = $data[$c];
                         $im_msn = "MSN";
                         $contact_im_msn_per_type = "Personal";
                         break;
                     case "im_msn_ot":
                         $contact_im_msn_ot = $data[$c];
                         $im_msn = "MSN";
                         $contact_im_msn_ot_type = "Other";
                         break;
                     case "im_icq_wk":
                         $contact_im_icq_wk = $data[$c];
                         $im_icq = "ICQ";
                         $contact_im_icq_wk_type = "Work";
                         break;
                     case "im_icq_per":
                         $contact_im_icq_per = $data[$c];
                         $im_icq = "ICQ";
                         $contact_im_icq_per_type = "Personal";
                         break;
                     case "im_icq_ot":
                         $contact_im_icq_ot = $data[$c];
                         $im_icq = "ICQ";
                         $contact_im_icq_ot_type = "Other";
                         break;
                     case "im_jabber_wk":
                         $contact_im_jabber_wk = $data[$c];
                         $im_jabber = "Jabber";
                         $contact_im_jabber_wk_type = "Work";
                         break;
                     case "im_jabber_per":
                         $contact_im_jabber_per = $data[$c];
                         $im_jabber = "Jabber";
                         $contact_im_jabber_per_type = "Personal";
                         break;
                     case "im_jabber_ot":
                         $contact_im_jabber_ot = $data[$c];
                         $im_jabber = "Jabber";
                         $contact_im_jabber_ot_type = "Other";
                     case "im_yahoo_wk":
                         $contact_im_yahoo_wk = $data[$c];
                         $im_yahoo = "Yahoo";
                         $contact_im_yahoo_wk_type = "Work";
                         break;
                     case "im_yahoo_per":
                         $contact_im_yahoo_per = $data[$c];
                         $im_yahoo = "Yahoo";
                         $contact_im_yahoo_per_type = "Personal";
                         break;
                     case "im_yahoo_ot":
                         $contact_im_yahoo_ot = $data[$c];
                         $im_yahoo = "Yahoo";
                         $contact_im_yahoo_ot_type = "Other";
                         break;
                     case "im_skype_wk":
                         $contact_im_skype_wk = $data[$c];
                         $im_skype = "Skype";
                         $contact_im_skype_wk_type = "Work";
                         break;
                     case "im_skype_per":
                         $contact_im_skype_per = $data[$c];
                         $im_skype = "Skype";
                         $contact_im_skype_per_type = "Personal";
                         break;
                     case "im_skype_ot":
                         $contact_im_skype_ot = $data[$c];
                         $im_skype = "Skype";
                         $contact_im_skype_ot_type = "Other";
                     case "im_gt_wk":
                         $contact_im_gt_wk = $data[$c];
                         $im_gt = "Google Talk";
                         $contact_im_gt_wk_type = "Work";
                         break;
                     case "im_gt_per":
                         $contact_im_gt_per = $data[$c];
                         $im_gt = "Google Talk";
                         $contact_im_gt_per_type = "Personal";
                         break;
                     case "im_gt_ot":
                         $contact_im_gt_ot = $data[$c];
                         $im_gt = "Google Talk";
                         $contact_im_gt_ot_type = "Other";
                         break;
                     case "note":
                         $contact_note .= "<p>" . $data[$c] . "</p>";
                         break;
                 }
             }
             $do_company->name = $company;
             $do_company->iduser = $iduser;
             $do_company->add();
             $idcompany = $do_company->getPrimaryKeyValue();
             $do_contact->idcompany = $idcompany;
             $do_contact->iduser = $iduser;
             $do_contact->firstname = $contact_firstname;
             $do_contact->lastname = $contact_lastname;
             $do_contact->company = $contact_company;
             $do_contact->position = $contact_position;
             $do_contact->summary = $contact_summary;
             $do_contact->birthday = $contact_birthday;
             $do_contact->add();
             $idcontact = $do_contact->getPrimaryKeyValue();
             //In theory this below should not be needed
             $do_contact->idcontact = $idcontact;
             $do_tag = new Tag();
             if (strpos($_SESSION['import_tag'], ",") === false) {
                 $do_tag->addTagAssociation($idcontact, trim($_SESSION['import_tag']), "contact", $_SESSION['do_User']->iduser);
             } else {
                 $tags = explode(",", $_SESSION['import_tag']);
                 foreach ($tags as $tag) {
                     $do_tag->addTagAssociation($idcontact, trim($tag), "contact", $_SESSION['do_User']->iduser);
                 }
             }
             if ($contact_address_hm != "" || $contact_city != "" || $contact_state != "" || $contact_street != "" || $contact_zipcode != "" || $contact_country != "") {
                 $do_contact->addAddress($contact_address_hm, $contact_address_hm_type, $contact_city, $contact_state, $contact_street, $contact_zipcode, $contact_country);
             }
             if ($contact_address_wk != "" || $contact_city != "" || $contact_state != "" || $contact_street != "" || $contact_zipcode != "" || $contact_country != "") {
                 $do_contact->addAddress($contact_address_wk, $contact_address_wk_type, $contact_city, $contact_state, $contact_street, $contact_zipcode, $contact_country);
             }
             if ($contact_address_ot != "" || $contact_city != "" || $contact_state != "" || $contact_street != "" || $contact_zipcode != "" || $contact_country != "") {
                 $do_contact->addAddress($contact_address_ot, $contact_address_ot_type, $contact_city, $contact_state, $contact_street, $contact_zipcode, $contact_country);
             }
             if ($contact_email_hm != "") {
                 $do_contact->addEmail($contact_email_hm, $contact_email_hm_type);
             }
             if ($contact_email_wk != "") {
                 $do_contact->addEmail($contact_email_wk, $contact_email_wk_type);
             }
             if ($contact_email_ot != "") {
                 $do_contact->addEmail($contact_email_ot, $contact_email_ot_type);
             }
             if ($contact_phone_hm != "") {
                 $do_contact->addPhone($contact_phone_hm, $contact_phone_hm_type);
             }
             if ($contact_phone_wk != "") {
                 $do_contact->addPhone($contact_phone_wk, $contact_phone_wk_type);
             }
             if ($contact_phone_ot != "") {
                 $do_contact->addPhone($contact_phone_ot, $contact_phone_ot_type);
             }
             if ($contact_phone_mb != "") {
                 $do_contact->addPhone($contact_phone_mb, $contact_phone_mb_type);
             }
             if ($contact_phone_fx != "") {
                 $do_contact->addPhone($contact_phone_fx, $contact_phone_fx_type);
             }
             if ($contact_website_comp != "") {
                 $do_contact->addWebsite($contact_website_comp, $contact_website_comp_type);
             }
             if ($contact_website_blog != "") {
                 $do_contact->addWebsite($contact_website_blog, $contact_website_blog_type);
             }
             if ($contact_website_ot != "") {
                 $do_contact->addWebsite($contact_website_ot, $contact_website_ot_type);
             }
             if ($contact_website_personal != "") {
                 $do_contact->addWebsite($contact_website_personal, $contact_website_personal_type);
             }
             if ($contact_website_twitter != "") {
                 $do_contact->addWebsite($contact_website_twitter, $contact_website_twitter_type);
             }
             if ($contact_website_linkedin != "") {
                 $do_contact->addWebsite($contact_website_linkedin, $contact_website_linkedin_type);
             }
             if ($contact_website_fb != "") {
                 $do_contact->addWebsite($contact_website_fb, $contact_website_fb_type);
             }
             if ($contact_im_aim_wk != "") {
                 $do_contact->addIM($im_aim, $contact_im_aim_wk_type, $contact_im_aim_wk);
             }
             if ($contact_im_aim_per != "") {
                 $do_contact->addIM($im_aim, $contact_im_aim_per_type, $contact_im_aim_per);
             }
             if ($contact_im_aim_ot != "") {
                 $do_contact->addIM($im_aim, $contact_im_aim_ot_type, $contact_im_aim_ot);
             }
             if ($contact_im_msn_wk != "") {
                 $do_contact->addIM($im_msn, $contact_im_msn_wk_type, $contact_im_msn_wk);
             }
             if ($contact_im_msn_per != "") {
                 $do_contact->addIM($im_msn, $contact_im_msn_per_type, $contact_im_msn_per);
             }
             if ($contact_im_msn_ot != "") {
                 $do_contact->addIM($im_msn, $contact_im_msn_ot_type, $contact_im_msn_ot);
             }
             if ($contact_im_icq_wk != "") {
                 $do_contact->addIM($im_icq, $contact_im_icq_wk_type, $contact_im_icq_wk);
             }
             if ($contact_im_icq_per != "") {
                 $do_contact->addIM($im_icq, $contact_im_icq_per_type, $contact_im_icq_per);
             }
             if ($contact_im_icq_ot != "") {
                 $do_contact->addIM($im_icq, $contact_im_icq_ot_type, $contact_im_icq_ot);
             }
             if ($contact_im_jabber_wk != "") {
                 $do_contact->addIM($im_jabber, $contact_im_jabber_wk_type, $contact_im_jabber_wk);
             }
             if ($contact_im_jabber_per != "") {
                 $do_contact->addIM($im_jabber, $contact_im_jabber_per_type, $contact_im_jabber_per);
             }
             if ($contact_im_jabber_ot != "") {
                 $do_contact->addIM($im_jabber, $contact_im_jabber_ot_type, $contact_im_jabber_ot);
             }
             if ($contact_im_yahoo_wk != "") {
                 $do_contact->addIM($im_yahoo, $contact_im_yahoo_wk_type, $contact_im_yahoo_wk);
             }
             if ($contact_im_yahoo_per != "") {
                 $do_contact->addIM($im_yahoo, $contact_im_yahoo_per_type, $contact_im_yahoo_per);
             }
             if ($contact_im_yahoo_ot != "") {
                 $do_contact->addIM($im_yahoo, $contact_im_yahoo_ot_type, $contact_im_yahoo_ot);
             }
             if ($contact_im_skype_wk != "") {
                 $do_contact->addIM($im_skype, $contact_im_skype_wk_type, $contact_im_skype_wk);
             }
             if ($contact_im_skype_per != "") {
                 $do_contact->addIM($im_skype, $contact_im_skype_per_type, $contact_im_skype_per);
             }
             if ($contact_im_skype_ot != "") {
                 $do_contact->addIM($im_skype, $contact_im_skype_ot_type, $contact_im_skype_ot);
             }
             if ($contact_im_gt_wk != "") {
                 $do_contact->addIM($im_gt, $contact_im_gt_wk_type, $contact_im_gt_wk);
             }
             if ($contact_im_gt_per != "") {
                 $do_contact->addIM($im_gt, $contact_im_gt_per_type, $contact_im_gt_per);
             }
             if ($contact_im_gt_ot != "") {
                 $do_contact->addIM($im_gt, $contact_im_gt_ot_type, $contact_im_gt_ot);
             }
             if ($contact_note != "") {
                 $do_contact_notes->idcontact = $idcontact;
                 $do_contact_notes->iduser = $iduser;
                 $do_contact_notes->note = $contact_note;
                 $do_contact_notes->date_added = date('Y-m-d');
                 $do_contact_notes->add();
             }
             $do_cont_view = new ContactView();
             $do_cont_view->addFromContact($do_contact);
             $do_cont_view->updateFromContact($do_contact);
             // Added the method call updateFromContact() so that the child data is updated just after insert
             $do_cont_view->addTag($_SESSION['import_tag'], $do_contact->idcontact);
             // Update the contact view for tags.
             $do_contact->free();
             $do_company->free();
             $do_contact_notes->free();
         }
         $row++;
     }
     fclose($handle);
     $goto = $eventcontroler->getParam("goto");
     $disp = new Display($goto);
     $disp->addParam("message", "Contacts have been imported successfully.");
     $eventcontroler->setDisplayNext($disp);
 }
Beispiel #7
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);
 /**
  * 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);
         }
     }
 }
/** Generate bigdump : generate items for an entity
 *
 * @param $ID_entity entity ID
**/
function generate_entity($ID_entity) {
   global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK,
         $DOCUMENTS, $NET_PORT, $NET_LOC;

   regenerateTreeCompleteName("glpi_entities");

   $current_year = date("Y");


   // DOMAIN
   $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine");
   $dp    = new Domain();
   $FIRST["domain"] = getMaxItem("glpi_domains")+1;

   for ($i=0 ; $i<$MAX['domain'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "domain $ID_entity '$i";
      }
      $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1,
                                              'comment'      => "comment $val")));
   }
   $LAST["domain"] = getMaxItem("glpi_domains");


   // STATUS
   $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'");
   $dp    = new State();
   $FIRST["state"] = getMaxItem("glpi_states")+1;
   for ($i=0 ; $i<$MAX['state'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "State $ID_entity '$i";
      }
      $state_id = $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                                          'entities_id'  => $ID_entity,
                                                          'is_recursive' => 1,
                                                          'comment'      => "comment $val")));

      // generate sub status
      for ($j=0 ; $j<$MAX['state'] ; $j++) {
         $val2 = "Sub $val $j";

         $dp->add(toolbox::addslashes_deep(array('name'         => $val2,
                                                 'entities_id'  => $ID_entity,
                                                 'is_recursive' => 1,
                                                 'states_id'    => $state_id,
                                                 'comment'      => "comment $val")));
      }

   }
   $LAST["state"]      = getMaxItem("glpi_states");


   // glpi_groups
   $FIRST["groups"] = getMaxItem("glpi_groups")+1;
   $group           = new Group();
   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
      $gID = $group->add(toolbox::addslashes_deep(
                         array('entities_id'  => $ID_entity,
                               'name'         => "group d'$i",
                               'comment'      => "comment group d'$i",
                               'is_assign'    => 0)));

      // Generate sub group
      for ($j=0 ; $j<$MAX['groups'] ; $j++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "subgroup d'$j",
                           'comment'      => "comment subgroup d'$j of group $i",
                           'groups_id'    => $gID,
                           'is_assign'    => 0)));
      }
   }

   $LAST["groups"]      = getMaxItem("glpi_groups");

   $FIRST["techgroups"] = $LAST["groups"]+1;

   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "tech group d'$i",
                           'comment'      => "comment tech group d'$i")));
   }

   $LAST["techgroups"] = getMaxItem("glpi_groups");
   regenerateTreeCompleteName("glpi_groups");


   // glpi_users
   $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1;
   $user                  = new User();
   $gu                    = new Group_User();
   for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) {
      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "sadmin$i-$ID_entity",
                                   'password'           => "sadmin'$i",
                                   'password2'          => "sadmin'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "sadmin '$i name",
                                   'firstname'          => "sadmin '$i firstname",
                                   'comment'            => "comment' $i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 4,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1
                                   )));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups'])));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['techgroups'], $LAST['techgroups'])));
   }
   $LAST["users_sadmin"] = getMaxItem("glpi_users");
   $FIRST["users_admin"] = getMaxItem("glpi_users")+1;

   for ($i=0 ; $i<$MAX['users_admin'] ; $i++) {

      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "admin$i-$ID_entity",
                                   'password'           => "admin'$i",
                                   'password2'          => "admin'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "admin$i 'name",
                                   'firstname'          => "admin$i 'firstname",
                                   'comment'            => "comment '$i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 3,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1)));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups']),
                     'is_manager'   => 1,
                     'is_delegate'  => 1));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['techgroups'], $LAST['techgroups']),
                     'is_manager'   => 1,
                     'is_delegate'  => 1));
   }

   $LAST["users_admin"]   = getMaxItem("glpi_users");
   $FIRST["users_normal"] = getMaxItem("glpi_users")+1;

   for ($i=0 ; $i<$MAX['users_normal'] ; $i++) {
      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "normal$i-$ID_entity",
                                   'password'           => "normal'$i",
                                   'password2'          => "normal'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "normal$i 'name",
                                   'firstname'          => "normal$i 'firstname",
                                   'comment'            => "comment '$i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 2,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1)));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups'])));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['techgroups'], $LAST['techgroups'])));
   }

   $LAST["users_normal"]    = getMaxItem("glpi_users");
   $FIRST["users_postonly"] = getMaxItem("glpi_users")+1;

   for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) {
      $users_id = $user->add(toolbox::addslashes_deep(
                             array('name'               => "postonly$i-$ID_entity",
                                   'password'           => "postonly'$i",
                                   'password2'          => "postonly'$i",
                                   'phone'              => "tel $i",
                                   'phone2'             => "tel2 $i",
                                   'mobile'             => "mobile $i",
                                   'realname'           => "postonly$i 'name",
                                   'firstname'          => "postonly$i 'firstname",
                                   'comment'            => "comment' $i",
                                   'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                   'usercategories_id'  => mt_rand(0,$MAX['user_type']),
                                   '_profiles_id'       => 1,
                                   '_entities_id'       => $ID_entity,
                                   '_is_recursive'      => 1)));

      $gu->add(array('users_id'     => $users_id,
                     'groups_id'    => mt_rand($FIRST['groups'], $LAST['groups'])));
   }

   $LAST["users_postonly"] = getMaxItem("glpi_users");


   $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1;
   $kbc                   = new KnowbaseItemCategory();

   for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) {
      $newID = $kbc->add(toolbox::addslashes_deep(
                         array('entities_id'     => $ID_entity,
                               'is_recursive'    => 1,
                               'name'            => "entity ' categorie $i",
                               'comment'         => "comment ' categorie $i")));

      for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) {
         $newID2 = $kbc->add(toolbox::addslashes_deep(
                             array('entities_id'                 => $ID_entity,
                                   'is_recursive'                => 1,
                                   'name'                        => "entity s-categorie '$j",
                                   'comment'                     => "comment s-categorie '$j",
                                   'knowbaseitemcategories_id'   => $newID)));

         for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) {
            $newID2 = $kbc->add(toolbox::addslashes_deep(
                                array('entities_id'               => $ID_entity,
                                      'is_recursive'              => 1,
                                      'name'                      => "entity ss-categorie' $k",
                                      'comment'                   => "comment ss-categorie' $k",
                                      'knowbaseitemcategories_id' => $newID2)));
         }
      }
   }

   $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`";
   $DB->query($query) or die("PB REQUETE ".$query);

   regenerateTreeCompleteName("glpi_knowbaseitemcategories");
   $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories");


   // LOCATIONS
   $added              = 0;
   $FIRST["locations"] = getMaxItem("glpi_locations")+1;
   $loc                = new Location();
   for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) {
      $added++;
      $newID = $loc->add(toolbox::addslashes_deep(
                         array('entities_id'     => $ID_entity,
                               'is_recursive'    => 1,
                               'name'            => "location' $i",
                               'comment'         => "comment 'location $i",
                               'building'        => "building $i")));

      for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) {
         $added++;
         $newID2 = $loc->add(toolbox::addslashes_deep(
                             array('entities_id'     => $ID_entity,
                                   'is_recursive'    => 1,
                                   'name'            => "s-location '$j",
                                   'comment'         => "comment s-location '$j",
                                   'building'        => "building $i",
                                   'room'            => "stage '$j",
                                   'locations_id'    => $newID)));

         for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) {
            $added++;
            $newID3 = $loc->add(toolbox::addslashes_deep(
                                array('entities_id'     => $ID_entity,
                                      'is_recursive'    => 1,
                                      'name'            => "ss-location '$k",
                                      'comment'         => "comment ss-location' $k",
                                      'building'        => "building $i",
                                      'room'            => "part' $k",
                                      'locations_id'    => $newID2)));

            for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) {
               $added++;
               $newID4 = $loc->add(toolbox::addslashes_deep(
                                   array('entities_id'     => $ID_entity,
                                         'is_recursive'    => 1,
                                         'name'            => "sss-location' $l",
                                         'comment'         => "comment sss-location' $l",
                                         'building'        => "building $i",
                                         'room'            => "room' $l",
                                         'locations_id'    => $newID3)));

               for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) {
                  $added++;
                  $newID5 = $loc->add(toolbox::addslashes_deep(
                                      array('entities_id'     => $ID_entity,
                                            'is_recursive'    => 1,
                                            'name'            => "ssss-location' $m",
                                            'comment'         => "comment ssss-location' $m",
                                            'building'        => "building $i",
                                            'room'            => "room' $l-$m",
                                            'locations_id'    => $newID4)));
               }
            }
         }
      }
   }

   $query = "OPTIMIZE TABLE `glpi_locations`";
   $DB->query($query) or die("PB REQUETE ".$query);

   regenerateTreeCompleteName("glpi_locations");
   $LAST["locations"]=getMaxItem("glpi_locations");


   // Task categories
   $added                 = 0;
   $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1;
   $tc                    = new TaskCategory();
   for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) {
      $added++;
      $newID = $tc->add(toolbox::addslashes_deep(
                        array('entities_id'     => $ID_entity,
                              'is_recursive'    => 1,
                              'name'            => "ent$ID_entity taskcategory' $i",
                              'comment'         => "comment ent$ID_entity taskcategory' $i")));

      for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) {
         $newID2 = $tc->add(toolbox::addslashes_deep(
                            array('entities_id'        => $ID_entity,
                                  'is_recursive'       => 1,
                                  'name'               => "ent$ID_entity taskcategory' $i",
                                  'comment'            => "comment ent$ID_entity taskcategory' $i",
                                  'taskcategories_id'  => $newID)));
         $added++;
      }
   }

   $query = "OPTIMIZE TABLE `glpi_taskcategories`";
   $DB->query($query) or die("PB REQUETE ".$query);

   regenerateTreeCompleteName("glpi_taskcategories");
   $LAST["taskcategory"] = getMaxItem("glpi_taskcategories");

   $ic = new ItilCategory();
   // Specific ticket categories
   $newID = $ic->add(toolbox::addslashes_deep(
                     array('entities_id'     => $ID_entity,
                           'is_recursive'    => 1,
                           'name'            => "category for entity' $ID_entity",
                           'comment'         => "comment category for entity' $ID_entity",
                           'users_id'        => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']),
                           'groups_id'       => mt_rand($FIRST['techgroups'],$LAST['techgroups']),
                           'tickettemplates_id_incident' => 1,
                           'tickettemplates_id_demand'   => 1)));

   for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) {
      $ic->add(toolbox::addslashes_deep(
               array('entities_id'                 => $ID_entity,
                     'is_recursive'                => 1,
                     'name'                        => "scategory for entity' $ID_entity",
                     'comment'                     => "comment scategory for entity' $ID_entity",
                     'users_id'                    => mt_rand($FIRST['users_sadmin'],
                                                              $LAST['users_admin']),
                     'groups_id'                   => mt_rand($FIRST['techgroups'],
                                                              $LAST['techgroups']),
                     'tickettemplates_id_incident' => 1,
                     'tickettemplates_id_demand'   => 1,
                     'itilcategories_id'           => $newID)));
   }

   regenerateTreeCompleteName("glpi_itilcategories");

   $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1;

   $items = array("d'après KB");
   $st    = new SolutionType();
   for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "type de solution ' $i";
      }
      $st->add(toolbox::addslashes_deep(array('name'         => $val,
                                              'comment'      => "comment $val",
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1)));
   }
   $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes");


   $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1;
   $nb_items                   = mt_rand(0,$MAX['solutiontemplates']);
   $st                         = new SolutionTemplate();
   for ($i=0 ; $i<$nb_items ; $i++) {
      $st-> add(toolbox::addslashes_deep(
                array('entities_id'        => $ID_entity,
                      'is_recursive'       => 1,
                      'name'               => "solution' $i-$ID_entity",
                      'content'            => "content solution' $i-$ID_entity",
                      'solutiontypes_id'   => mt_rand(0,$MAX['solutiontypes']),
                      'comment'            => "comment solution' $i-$ID_entity")));
   }

   $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates");

   // Add Specific questions
   $k                = 0;
   $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1;
   $ki               = new KnowbaseItem();
   $eki              = new Entity_KnowbaseItem();
   for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) {
      $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT);
      for ($j=0 ; $j<$nb ; $j++) {
         $k++;
         $newID = $ki->add(toolbox::addslashes_deep(
                           array('knowbaseitemcategories_id'   => $i,
                                 'name'      => "Entity' $ID_entity Question $k",
                                 'answer'    => "Answer' $k".Toolbox::getRandomString(50),
                                 'is_faq'    => mt_rand(0,1),
                                 'users_id'  => mt_rand($FIRST['users_sadmin'],
                                                        $LAST['users_admin']))));

         $eki->add(array('entities_id'       => $ID_entity,
                        'knowbaseitems_id'   => $newID,
                        'is_recursive'       => 0));
      }
   }


   // Add global questions
   for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) {
      $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT);
      for ($j=0 ; $j<$nb ; $j++) {
         $k++;
         $newID = $ki->add(toolbox::addslashes_deep(
                           array('knowbaseitemcategories_id'   => $i,
                                 'name'      => "Entity' $ID_entity Recursive Question $k",
                                 'answer'    => "Answer' $k".Toolbox::getRandomString(50),
                                 'is_faq'    => mt_rand(0,1),
                                 'users_id'  => mt_rand($FIRST['users_sadmin'],
                                                        $LAST['users_admin']))));

         $eki->add(array('entities_id'       => $ID_entity,
                        'knowbaseitems_id'   => $newID,
                        'is_recursive'       => 1));
      }
   }

   $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems");


   // Ajout documents  specific
   $FIRST["document"] = getMaxItem("glpi_documents")+1;
   $doc               = new Document();
   for ($i=0 ; $i<$MAX['document'] ; $i++) {
      $link = "";
      if (mt_rand(0,100)<50) {
         $link = "http://linktodoc/doc$i";
      }

      $docID = $doc->add(toolbox::addslashes_deep(
                         array('entities_id'           => $ID_entity,
                               'is_recursive'          => 0,
                               'name'                  => "document' $i-$ID_entity",
                               'documentcategories_id' => mt_rand(1,$MAX['rubdocs']),
                               'comment'               => "commen't $i",
                               'link'                  => $link,
                               'notepad'               => "notes document' $i")));

      $DOCUMENTS[$docID] = $ID_entity."-0";
   }


   // Global ones
   for ($i=0 ; $i<$MAX['document']/2 ; $i++) {
      $link = "";
      if (mt_rand(0,100)<50) {
         $link = "http://linktodoc/doc$i";
      }

      $docID = $doc->add(toolbox::addslashes_deep(
                         array('entities_id'           => $ID_entity,
                               'is_recursive'          => 1,
                               'name'                  => "Recursive document' $i-$ID_entity",
                               'documentcategories_id' => mt_rand(1,$MAX['rubdocs']),
                               'comment'               => "comment' $i",
                               'link'                  => $link,
                               'notepad'               => "notes document' $i")));

      $DOCUMENTS[$docID] = $ID_entity."-1";
   }

   $LAST["document"] = getMaxItem("glpi_documents");


   // Ajout budgets  specific
   $FIRST["budget"] = getMaxItem("glpi_budgets")+1;
   $b               = new Budget();
   for ($i=0 ; $i<$MAX['budget'] ; $i++) {
      $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
      $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans

      $b->add(toolbox::addslashes_deep(
              array('name'         => "budget' $i-$ID_entity",
                    'entities_id'  => $ID_entity,
                    'is_recusive'  => 0,
                    'comment'      => "comment' $i-$ID_entity",
                    'begin_date'   => date("Y-m-d",intval($date1)),
                    'end_date'     => date("Y-m-d",intval($date2)))));
   }
   $LAST["budget"] = getMaxItem("glpi_budgets");

   // GLobal ones
   for ($i=0 ; $i<$MAX['document']/2 ; $i++) {
      $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
      $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans

      $b->add(toolbox::addslashes_deep(
              array('name'         => "Recursive budget' $i-$ID_entity",
                    'entities_id'  => $ID_entity,
                    'is_recusive'  => 1,
                    'comment'      => "comment' $i-$ID_entity",
                    'begin_date'   => date("Y-m-d",intval($date1)),
                    'end_date'     => date("Y-m-d",intval($date2)))));

   }
   $LAST["document"] = getMaxItem("glpi_documents");


   // glpi_suppliers
   $items                = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox",
                                 "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark");
   $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1;
   $ent                  = new Supplier();

   // Global ones
   for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) {
      if (isset($items[$i])) {
         $val = "Recursive ".$items[$i];
      } else {
         $val = "Recursive enterprise_".$i."_ID_entity";
      }
      $entID = $ent->add(toolbox::addslashes_deep(
                         array('entities_id'        => $ID_entity,
                               'is_recursive'       => 1,
                               'name'               => "Recursive' $val-$ID_entity",
                               'suppliertypes_id'   => mt_rand(1,$MAX['enttype']),
                               'address'            => "address' $i",
                               'postcode'           => "postcode $i",
                               'town'               => "town' $i",
                               'state'              => "state' $i",
                               'country'            => "country $i",
                               'website'            => "http://www.$val.com/",
                               'fax'                => "fax $i",
                               'email'              => "info@ent$i.com",
                               'notepad'            => "notes enterprises' $i")));

      addDocuments('Supplier', $entID);
   }


   // Specific ones
   for ($i=0 ; $i<$MAX['enterprises'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "enterprise_".$i."_ID_entity";
      }

      $entID = $ent->add(toolbox::addslashes_deep(
                         array('entities_id'        => $ID_entity,
                               'is_recursive'       => 0,
                               'name'               => "'$val-$ID_entity",
                               'suppliertypes_id'   => mt_rand(1,$MAX['enttype']),
                               'address'            => "address' $i",
                               'postcode'           => "postcode $i",
                               'town'               => "town' $i",
                               'state'              => "state' $i",
                               'country'            => "country $i",
                               'website'            => "http://www.$val.com/",
                               'fax'                => "fax $i",
                               'email'              => "info@ent$i.com",
                               'notepad'            => "notes supplier' $i",
                               'comment'            => "comment supplier' $i")));

      addDocuments('Supplier', $entID);
   }
   $LAST["enterprises"] = getMaxItem("glpi_suppliers");


   // Ajout contracts
   $FIRST["contract"] = getMaxItem("glpi_contracts")+1;
   $c                 = new Contract();
   $cs                = new Contract_Supplier();
   $cc                = new ContractCost();
   // Specific
   for ($i=0 ; $i<$MAX['contract'] ; $i++) {
      $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28);
      $contractID = $c->add(toolbox::addslashes_deep(
                            array('entities_id'        => $ID_entity,
                                  'is_recursive'       => 0,
                                  'name'               => "contract' $i-$ID_entity",
                                  'num'                => "num' $i",
                                  'contracttypes_id'   => mt_rand(1,$MAX['contract_type']),
                                  'begin_date'         => $date,
                                  'duration'           => mt_rand(1,36),
                                  'notice'             => mt_rand(1,3),
                                  'periodicity'        => mt_rand(1,36),
                                  'billing'            => mt_rand(1,36),
                                  'comment'            => "comment' $i",
                                  'accounting_number'  => "compta num' $i",
                                  'renewal'            => 1)));

      addDocuments('Contract', $contractID);

      // Add an enterprise
      $cs->add(array('contracts_id' => $contractID,
                     'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"])));
      // Add a cost
      $cc->add(toolbox::addslashes_deep(
               array('contracts_id' => $contractID,
                     'cost'         => mt_rand(100,10000),
                     'name'         => "Initial 'cost",
                     'begin_date'   => $date,
                     'budgets_id'   => mt_rand($FIRST['budget'], $LAST['budget']))));
   }

   for ($i=0 ; $i<$MAX['contract']/2 ; $i++) {
      $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28);

      $contractID = $c->add(toolbox::addslashes_deep(
                            array('entities_id'        => $ID_entity,
                                  'is_recursive'       => 1,
                                  'name'               => "Recursive contract' $i-$ID_entity",
                                  'num'                => "num' $i",
                                  'cost'               => mt_rand(100,10000),
                                  'contracttypes_id'   => mt_rand(1,$MAX['contract_type']),
                                  'begin_date'         => $date,
                                  'duration'           => mt_rand(1,36),
                                  'notice'             => mt_rand(1,3),
                                  'periodicity'        => mt_rand(1,36),
                                  'billing'            => mt_rand(1,36),
                                  'comment'            => "comment' $i",
                                  'accounting_number'  => "compta num' $i",
                                  'renewal'            => 1)));

      addDocuments('Contract', $contractID);

      // Add an enterprise
      $cs->add(array('contracts_id' => $contractID,
                     'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"])));
   }
   $LAST["contract"] = getMaxItem("glpi_contracts");


   // Ajout contacts
   $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste",
                    "Albert", "Julien", "Guillaume", "Bruno",
                    "Maurice", "Francois", "Laurent", "Richard",
                    "Henri", "Clement", "d'avy");
   $noms    = array("Dupont", "Smith", "Durand", "Martin", "Dubois",
                    "Dufour", "Dupin", "Duval", "Petit", "Grange",
                    "Bernard", "Bonnet", "Richard", "Leroy",
                    "Dumont", "Fontaine", "d'orleans");


   $FIRST["contacts"] = getMaxItem("glpi_contacts")+1;
   $c                 = new Contact();
   $cs                = new Contact_Supplier();
   for ($i=0 ; $i<$MAX['contacts'] ; $i++) {
      if (isset($noms[$i])) {
         $val = $noms[$i];
      } else {
         $val = "name $i";
      }
      if (isset($prenoms[$i])) {
         $val2 = $prenoms[$i];
      } else {
         $val2 = "firstname $i";
      }

      $contactID = $c->add(toolbox::addslashes_deep(
                           array('entities_id'        => $ID_entity,
                                 'is_recursive'       => 0,
                                 'name'               => "$val-$ID_entity",
                                 'firstname'          => $val2,
                                 'contacttypes_id'    => mt_rand(1,$MAX['contact_type']),
                                 'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                 'phone'              => "phone $i",
                                 'phone2'             => "phone2 $i",
                                 'mobile'             => "mobile $i",
                                 'fax'                => "fax $i",
                                 'email'              => "email $i",
                                 'address'            => "address' $i",
                                 'postcode'           => "postcode $i",
                                 'town'               => "town' $i",
                                 'state'              => "state' $i",
                                 'country'            => "country $i",
                                 'comment'            => "Comment' $i")));

      // Link with enterprise
      $cs->add(array('contacts_id'  => $contactID,
                     'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises'])));
   }

   for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) {
      if (isset($items[$i])) {
         $val = "Recursive ".$items[$i];
      } else {
         $val = "Recursive contact $i";
      }
      $contactID = $c->add(toolbox::addslashes_deep(
                           array('entities_id'        => $ID_entity,
                                 'is_recursive'       => 0,
                                 'name'               => "$val'-$ID_entity",
                                 'contacttypes_id'    => mt_rand(1,$MAX['contact_type']),
                                 'usertitles_id'      => mt_rand(0,$MAX['user_title']),
                                 'phone'              => "phone $i",
                                 'phone2'             => "phone2 $i",
                                 'mobile'             => "mobile $i",
                                 'fax'                => "fax $i",
                                 'email'              => "email $i",
                                 'address'            => "address' $i",
                                 'postcode'           => "postcode $i",
                                 'town'               => "town' $i",
                                 'state'              => "state' $i",
                                 'country'            => "country $i",
                                 'comment'            => "Comment' $i")));

      // Link with enterprise
      $cs->add(array('contacts_id'  => $contactID,
                     'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises'])));
   }
   $LAST["contacts"] = getMaxItem("glpi_contacts");


   // TYPE DE CONSOMMABLES
   $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1;
   $ci                           = new Consumableitem();

   for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) {
      $consID = $ci->add(toolbox::addslashes_deep(
                         array('entities_id'             => $ID_entity,
                               'is_recursive'            => mt_rand(0,1),
                               'name'                    => "consumable type' $i",
                               'ref'                     => "ref d' $i",
                               'locations_id'            => mt_rand($FIRST["locations"],
                                                                    $LAST['locations']),
                               'consumableitemtypes_id'  => mt_rand(0,$MAX['consumable_type']),
                               'manufacturers_id'        => mt_rand(1,$MAX['manufacturer']),
                               'users_id_tech'           => mt_rand($FIRST['users_sadmin'],
                                                                    $LAST['users_admin']),
                               'groups_id_tech'          => mt_rand($FIRST["groups"], $LAST["groups"]),
                               'comment'                 => "comment' $i",
                               'notepad'                 => "notes consumableitem' $i",
                               'alarm_threshold'         => mt_rand(0,10))));

      addDocuments('ConsumableItem', $consID);


      // AJOUT INFOCOMS
      addInfocoms('ConsumableItem', $consID, $ID_entity);

      // Ajout consommable en stock
      $c = new Consumable();
      for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) {
         $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28);

         $ID = $c->add(array('entities_id'        => $ID_entity,
                             'consumableitems_id' => $consID,
                             'date_in'            => $date));

         // AJOUT INFOCOMS
         addInfocoms('Consumable', $ID, $ID_entity);
      }


      // Ajout consommable donne
      for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) {
         $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28);

         $ID = $c->add(array('entities_id'        => $ID_entity,
                             'consumableitems_id' => $consID,
                             'date_in'            => $date,
                             'date_out'           => date("Y-m-d")));

         // AJOUT INFOCOMS
         addInfocoms('Consumable', $ID, $ID_entity);

      }

   }
   $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems");


   // TYPE DE CARTOUCHES
   $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1;
   $ct                          = new CartridgeItem();

   for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) {
      $cartID = $ct->add(toolbox::addslashes_deep(
                         array('entities_id'       => $ID_entity,
                               'is_recursive'      => mt_rand(0,1),
                               'name'              => "cartridge ' type $i",
                               'ref'               => "ref '$i",
                               'locations_id'      => mt_rand($FIRST["locations"], $LAST['locations']),
                               'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                               'users_id_tech'     => mt_rand($FIRST['users_sadmin'],
                                                              $LAST['users_admin']),
                               'groups_id_tech'    => mt_rand($FIRST["groups"], $LAST["groups"]),
                               'comment'           => "comment '$i",
                               'notepad'           => "notes cartridgeitem '$i",
                               'alarm_threshold'   => mt_rand(0,10))));

      addDocuments('CartridgeItem', $cartID);


      // AJOUT INFOCOMS
      addInfocoms('CartridgeItem', $cartID, $ID_entity);

      $c    = new Cartridge();
      $cipm = new CartridgeItem_PrinterModel();
      // Ajout cartouche en stock
      for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) {
         $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28);

         $ID = $c->add(array('entities_id'         => $ID_entity,
                             'cartridgeitems_id'   => $cartID,
                             'date_in'             => $date));

         // AJOUT INFOCOMS
         addInfocoms('Cartridge', $ID, $ID_entity);

      }

      // Assoc printer type to cartridge type
      $cipm->add(array('cartridgeitems_id'  => $cartID,
                       'printermodels_id'   => mt_rand(1,$MAX['type_printers']),
                     ));
   }
   $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems");


   // Networking
   $NET_LOC             = array();
   $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1;
   $FIRST["printers"]   = getMaxItem("glpi_printers")+1;
   $ne                  = new NetworkEquipment();
   $p                   = new Printer();
   $np                  = new Netpoint();
   $c                   = new Cartridge();

   foreach ($DB->request('glpi_locations') as $data) {
      $i          = $data["id"];
      $techID     = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $gtechID    = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);
      $infoIP     = getNextIP();
      $domainID   = mt_rand($FIRST['domain'],$LAST['domain']);
      $networkID  = mt_rand(1,$MAX['network']);

      // insert networking

      $netwID = $ne->add(toolbox::addslashes_deep(
                         array('entities_id'                   => $ID_entity,
                               'name'                          => "networking '$i-$ID_entity",
                               'ram'                           => mt_rand(32,256),
                               'serial'                        => Toolbox::getRandomString(10),
                               'otherserial'                   => Toolbox::getRandomString(10),
                               'contact'                       => "contact '$i",
                               'contact_num'                   => "num '$i",
                               'users_id_tech'                 => $techID,
                               'groups_id_tech'                => $gtechID,
                               'comment'                       => "comment '$i",
                               'locations_id'                  => $i,
                               'domains_id'                    => $domainID,
                               'networks_id'                   => $networkID,
                               'networkequipmenttypes_id'      => mt_rand(1,$MAX['type_networking']),
                               'networkequipmentmodels_id'     => mt_rand(1,$MAX['model_networking']),
                               'networkequipmentfirmwares_id'  => mt_rand(1,$MAX['firmware']),
                               'manufacturers_id'              => mt_rand(1,$MAX['enterprises']),
                               'mac'                           => getNextMAC(),
                               'ip'                            => $infoIP["ip"],
                               'notepad'                       => "notes networking '$i",
                               'users_id'                      => mt_rand($FIRST['users_sadmin'],
                                                                          $LAST['users_admin']),
                               'groups_id'                     => mt_rand($FIRST["groups"],
                                                                          $LAST["groups"]),
                               'states_id'                     => (mt_rand(0,100)<$percent['state']
                                                                     ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));
      $NET_LOC[$data['id']] = $netwID;
      addDocuments('NetworkEquipment', $netwID);
      addContracts('NetworkEquipment', $netwID);

      // AJOUT INFOCOMS
      addInfocoms('NetworkEquipment', $netwID, $ID_entity);

      // Link with father
      addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i);

      // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches
      // Add trackings
      addTracking('NetworkEquipment', $netwID, $ID_entity);

      $typeID  = mt_rand(1,$MAX['type_printers']);
      $modelID = mt_rand(1,$MAX['model_printers']);
      $recur   = mt_rand(0,1);

      $printID = $p->add(toolbox::addslashes_deep(
                         array('entities_id'      => $ID_entity,
                                'is_recursive'     => $recur,
                                'name'             => "printer of loc '$i",
                                'serial'           => Toolbox::getRandomString(10),
                                'otherserial'      => Toolbox::getRandomString(10),
                                'contact'          => "contact '$i",
                                'contact_num'      => "num' $i",
                                'users_id_tech'    => $techID,
                                'groups_id_tech'   => $gtechID,
                                'have_serial'      => mt_rand(0,1),
                                'have_parallel'    => mt_rand(0,1),
                                'have_usb'         => mt_rand(0,1),
                                'have_wifi'        => mt_rand(0,1),
                                'have_ethernet'    => mt_rand(0,1),
                                'comment'          => "comment' $i",
                                'memory_size'      => mt_rand(0,128),
                                'locations_id'     => $i,
                                'domains_id'       => $domainID,
                                'networks_id'      => $networkID,
                                'printertypes_id'  => $typeID,
                                'printermodels_id' => $modelID,
                                'manufacturers_id' => mt_rand(1,$MAX['enterprises']),
                                'is_global'        => 1,
                                'notepad'          => "notes printers '$i",
                                'users_id'         => mt_rand($FIRST['users_sadmin'],
                                                              $LAST['users_admin']),
                                'groups_id'        => mt_rand($FIRST["groups"], $LAST["groups"]),
                                'states_id'        => (mt_rand(0,100)<$percent['state']
                                                         ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));

      addDocuments('Printer', $printID);
      addContracts('Printer', $printID);

      // Add trackings
      addTracking('Printer', $printID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Printer', $printID, $ID_entity, $recur);

      // Add Cartouches
      // Get compatible cartridge
      $query = "SELECT `cartridgeitems_id`
                FROM `glpi_cartridgeitems_printermodels`
                WHERE `printermodels_id` = '$typeID'";
      $result2 = $DB->query($query) or die("PB REQUETE ".$query);

      if ($DB->numrows($result2)>0) {
         $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query);
         $printed = 0;
         $oldnb   = mt_rand(1,$MAX['cartridges_by_printer']);
         $date1   = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
         $date2   = time();
         $inter   = abs(round(($date2-$date1)/$oldnb));

         // Add old cartridges
         for ($j=0 ; $j<$oldnb ; $j++) {
            $printed += mt_rand(0,5000);
            $c->add(array('entities_id'        => $ID_entity,
                          'cartridgeitems_id'  => $ctypeID,
                          'printers_id'        => $printID,
                          'date_in'            => date("Y-m-d",$date1),
                          'date_use'           => date("Y-m-d",$date1+$j*$inter),
                          'date_out'           => date("Y-m-d",$date1+($j+1)*$inter),
                          'pages'              => $printed));
         }

         // Add current cartridges
         $c->add(array('entities_id'        => $ID_entity,
                       'cartridgeitems_id'  => $ctypeID,
                       'printers_id'        => $printID,
                       'date_in'            => $date,
                       'date_use'           => date("Y-m-d",$date2)));
      }

      $iface = mt_rand(1,$MAX['iface']);

      // Add networking ports
      addNetworkEthernetPort('Printer', $printID, $ID_entity, $i);
   }
   unset($NET_LOC);
   $LAST["networking"] = getMaxItem("glpi_networkequipments");


   //////////// INVENTORY

   // glpi_computers
   $FIRST["computers"]   = getMaxItem("glpi_computers")+1;
   $FIRST["monitors"]    = getMaxItem("glpi_monitors")+1;
   $FIRST["phones"]      = getMaxItem("glpi_phones")+1;
   $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1;
   $c       = new Computer();
   $mon     = new Monitor();

   $cdevmb    = new Item_DeviceMotherBoard();
   $cdevproc  = new Item_DeviceProcessor();
   $cdevmem   = new Item_DeviceMemory();
   $cdevhd    = new Item_DeviceHardDrive();
   $cdevnc    = new Item_DeviceNetworkCard();
   $cdevdr    = new Item_DeviceDrive();
   $cdevcon   = new Item_DeviceControl();
   $cdevgc    = new Item_DeviceGraphicCard();
   $cdevsc    = new Item_DeviceSoundCard();
   $cdevpci   = new Item_DevicePci();
   $cdevcase  = new Item_DeviceCase();
   $cdevps    = new Item_DevicePowerSupply();

   $cdisk   = new ComputerDisk();
   $np      = new Netpoint();
   $ci      = new Computer_Item();
   $phone   = new Phone();
   $print   = new Printer();
   $periph  = new Peripheral();
   $cart    = new Cartridge();
   for ($i=0 ; $i<$MAX['computers'] ; $i++) {
      $loc       = mt_rand($FIRST["locations"],$LAST['locations']);
      $techID    = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $userID    = mt_rand($FIRST['users_normal'],$LAST['users_postonly']);
      $groupID   = mt_rand($FIRST["groups"],$LAST["groups"]);
      $gtechID   = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);
      $domainID  = mt_rand($FIRST['domain'],$LAST['domain']);
      $networkID = mt_rand(1,$MAX['network']);

      $compID = $c->add(toolbox::addslashes_deep(
                        array('entities_id'                    => $ID_entity,
                              'name'                           => "computer ' $i-$ID_entity",
                              'serial'                         => Toolbox::getRandomString(10),
                              'otherserial'                    => Toolbox::getRandomString(10),
                              'contact'                        => "contact' $i",
                              'contact_num'                    => "num' $i",
                              'users_id_tech'                  => $techID,
                              'groups_id_tech'                 => $gtechID,
                              'comment'                        => "comment' $i",
                              'operatingsystems_id'            => mt_rand(1,$MAX['os']),
                              'operatingsystemversions_id'     => mt_rand(1,$MAX['os_version']),
                              'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']),
                              'os_license_number'              => "os sn $i",
                              'os_licenseid'                   => "os id $i",
                              'autoupdatesystems_id'           => mt_rand(1,$MAX['os_sp']),
                              'locations_id'                   => $loc,
                              'domains_id'                     => $domainID,
                              'networks_id'                    => $networkID,
                              'computertypes_id'               => mt_rand(1,$MAX['type_computers']),
                              'computermodels_id'              => mt_rand(1,$MAX['model']),
                              'manufacturers_id'               => mt_rand(1,$MAX['manufacturer']),
                              'is_global'                      => 1,
                              'notepad'                        => "notes computer '$i",
                              'users_id'                       => $userID,
                              'groups_id'                      => $groupID,
                              'states_id'                      => (mt_rand(0,100)<$percent['state']
                                                                     ?mt_rand($FIRST['state'],$LAST['state']):0),
                              'uuid'                           => Toolbox::getRandomString(30)
                           )));

      addDocuments('Computer', $compID);
      addContracts('Computer', $compID);

      $NET_PORT['Computer'][$compID] = 0;

      // Add trackings
      addTracking('Computer', $compID, $ID_entity);

      // Add reservation
      addReservation('Computer', $compID, $ID_entity);


      // AJOUT INFOCOMS
      addInfocoms('Computer', $compID, $ID_entity);

      // ADD DEVICE
      $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $max   = mt_rand(1,4);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevproc->addDevices(1, 'Computer', $compID, $devid,
                               array('serial' => Toolbox::getRandomString(15)));
      }
      $max   = mt_rand(1,4);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevmem->addDevices(1, 'Computer', $compID, $devid,
                              array('serial' => Toolbox::getRandomString(15)));
      }

      $max = mt_rand(1,2);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevhd->addDevices(1, 'Computer', $compID, $devid,
                             array('serial' => Toolbox::getRandomString(15)));
      }

      $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15),
                                'mac'    => getNextMAC()));

      $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                           array('serial' => Toolbox::getRandomString(15)));

      $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                          array('serial' => Toolbox::getRandomString(15)));

      $max = mt_rand(1,4);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                              array('serial' => Toolbox::getRandomString(15)));
      }

      $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']),
                            array('serial'=> Toolbox::getRandomString(15)));

      $max   = mt_rand(1,2);
      $devid = mt_rand(1,$MAX['device']);
      for($nb = 0; $nb<$max; $nb++) {
         $cdevps->addDevices(1, 'Computer', $compID, $devid,
                             array('serial' => Toolbox::getRandomString(15)));
      }

      // insert disk
      $nb_disk = mt_rand(1,$MAX_DISK);
      for ($j=1 ; $j<=$nb_disk ; $j++) {
         $totalsize = mt_rand(10000,1000000);
         $freesize  = mt_rand(0,$totalsize);

         $cdisk->add(toolbox::addslashes_deep(
                      array('entities_id'     => $ID_entity,
                            'computers_id'    => $compID,
                            'name'            => "disk '$j",
                            'device'          => "/dev/disk$j",
                            'mountpoint'      => "/mnt/disk$j",
                            'filesystems_id'  => mt_rand(1,10),
                            'totalsize'       => $totalsize,
                            'freesize'        => $freesize)));
      }


      // Add networking ports
      addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc);

      // Ajout d'un ecran sur l'ordi
      $monID = $mon->add(toolbox::addslashes_deep(
                         array('entities_id'       => $ID_entity,
                               'name'              => "monitor' $i-$ID_entity",
                               'serial'            => Toolbox::getRandomString(10),
                               'otherserial'       => Toolbox::getRandomString(10),
                               'contact'           => "contact' $i",
                               'contact_num'       => "num' $i",
                               'users_id_tech'     => $techID,
                               'groups_id_tech'    => $gtechID,
                               'comment'           => "comment' $i",
                               'size'              => mt_rand(14,22),
                               'have_micro'        => mt_rand(0,1),
                               'have_speaker'      => mt_rand(0,1),
                               'have_subd'         => mt_rand(0,1),
                               'have_bnc'          => mt_rand(0,1),
                               'have_dvi'          => mt_rand(0,1),
                               'have_pivot'        => mt_rand(0,1),
                               'have_hdmi'         => mt_rand(0,1),
                               'have_displayport'  => mt_rand(0,1),
                               'locations_id'      => $loc,
                               'monitortypes_id'   => mt_rand(1,$MAX['type_monitors']),
                               'monitormodels_id'  => mt_rand(1,$MAX['model_monitors']),
                               'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                               'notepad'           => "notes monitor' $i",
                               'users_id'          => $userID,
                               'groups_id'         => $groupID,
                               'states_id'         => (mt_rand(0,100)<$percent['state']
                                                         ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));

      addDocuments('Monitor', $monID);
      addContracts('Monitor', $monID);

      // Add trackings
      addTracking('Monitor', $monID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Monitor', $monID, $ID_entity);

      $ci->add(array('itemtype'     => 'Monitor',
                     'items_id'     => $monID,
                     'computers_id' => $compID,
      ));

      // Ajout d'un telephhone avec l'ordi
      $telID = $phone->add(toolbox::addslashes_deep(
                           array('entities_id'           => $ID_entity,
                                 'name'                  => "phone' $i-$ID_entity",
                                 'serial'                => Toolbox::getRandomString(10),
                                 'otherserial'           => Toolbox::getRandomString(10),
                                 'contact'               => "contact' $i",
                                 'contact_num'           => "num' $i",
                                 'users_id_tech'         => $techID,
                                 'groups_id_tech'        => $gtechID,
                                 'comment'               => "comment' $i",
                                 'firmware'              => Toolbox::getRandomString(10),
                                 'brand'                 => "brand' $i",
                                 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']),
                                 'number_line'           => Toolbox::getRandomString(10),
                                 'have_headset'          => mt_rand(0,1),
                                 'have_hp'               => mt_rand(0,1),
                                 'locations_id'          => $loc,
                                 'phonetypes_id'         => mt_rand(1,$MAX['type_phones']),
                                 'phonemodels_id'        => mt_rand(1,$MAX['model_phones']),
                                 'manufacturers_id'      => mt_rand(1,$MAX['manufacturer']),
                                 'notepad'               => "notes phone' $i",
                                 'users_id'              => $userID,
                                 'groups_id'             => $groupID,
                                 'states_id'             => (mt_rand(0,100)<$percent['state']
                                                               ?mt_rand($FIRST['state'],$LAST['state']):0)
                           )));

      addDocuments('Phone', $telID);
      addContracts('Phone', $telID);

      // Add trackings
      addTracking('Phone', $telID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Phone', $telID, $ID_entity);

      $ci->add(array('itemtype'     => 'Phone',
                     'items_id'     => $telID,
                     'computers_id' => $compID));

      // Ajout des periphs externes en connection directe
      while (mt_rand(0,100)<$percent['peripherals']) {

         $periphID = $periph->add(toolbox::addslashes_deep(
                                  array('entities_id'       => $ID_entity,
                                        'name'              => "periph of comp' $i-$ID_entity",
                                        'serial'            => Toolbox::getRandomString(10),
                                        'otherserial'       => Toolbox::getRandomString(10),
                                        'contact'           => "contact' $i",
                                        'contact_num'       => "num' $i",
                                        'users_id_tech'     => $techID,
                                        'groups_id_tech'    => $gtechID,
                                        'comment'           => "comment' $i",
                                        'brand'             => "brand' $i",
                                        'locations_id'      => $loc,
                                        'phonetypes_id'     => mt_rand(1,$MAX['type_peripherals']),
                                        'phonemodels_id'    => mt_rand(1,$MAX['model_peripherals']),
                                        'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                                        'notepad'           => "notes peripheral' $i",
                                        'users_id'          => $userID,
                                        'groups_id'         => $groupID,
                                        'states_id'         => (mt_rand(0,100)<$percent['state']
                                                                  ?mt_rand($FIRST['state'],$LAST['state']):0)
                                    )));

         addDocuments('Peripheral', $periphID);
         addContracts('Peripheral', $periphID);

         // Add trackings
         addTracking('Peripheral', $periphID, $ID_entity);

         // Add connection
         $ci->add(array('itemtype'     => 'Peripheral',
                        'items_id'     => $periphID,
                        'computers_id' => $compID));
      }


      // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches
      if (mt_rand(0,100)<=$percent['printer']) {
         // Add printer
         $typeID  = mt_rand(1,$MAX['type_printers']);
         $modelID = mt_rand(1,$MAX['model_printers']);

         $printID = $p->add(toolbox::addslashes_deep(
                            array('entities_id'       => $ID_entity,
                                  'name'              => "printer of comp' $i-$ID_entity",
                                  'serial'            => Toolbox::getRandomString(10),
                                  'otherserial'       => Toolbox::getRandomString(10),
                                  'contact'           => "contact' $i",
                                  'contact_num'       => "num' $i",
                                  'users_id_tech'     => $techID,
                                  'groups_id_tech'    => $gtechID,
                                  'have_serial'       => mt_rand(0,1),
                                  'have_parallel'     => mt_rand(0,1),
                                  'have_usb'          => mt_rand(0,1),
                                  'have_wifi'         => mt_rand(0,1),
                                  'have_ethernet'     => mt_rand(0,1),
                                  'comment'           => "comment' $i",
                                  'memory_size'       => mt_rand(0,128),
                                  'locations_id'      => $loc,
                                  'domains_id'        => $domainID,
                                  'networks_id'       => $networkID,
                                  'printertypes_id'   => $typeID,
                                  'printermodels_id'  => $modelID,
                                  'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                                  'notepad'           => "notes printers '$i",
                                  'users_id'          => mt_rand($FIRST['users_postonly'],
                                                                 $LAST['users_postonly']),
                                  'groups_id'         => mt_rand($FIRST["groups"], $LAST["groups"]),
                                  'states_id'         => (mt_rand(0,100)<$percent['state']
                                                            ?mt_rand($FIRST['state'],$LAST['state']):0)
                              )));

         addDocuments('Printer', $printID);
         addContracts('Printer', $printID);

         // Add trackings
         addTracking('Printer', $printID, $ID_entity);

         // Add connection
         $ci->add(array('itemtype'     => 'Printer',
                        'items_id'     => $printID,
                        'computers_id' => $compID));

         // AJOUT INFOCOMS
         addInfocoms('Printer', $printID, $ID_entity);

         // Add Cartouches
         // Get compatible cartridge
         $query = "SELECT `cartridgeitems_id`
                   FROM `glpi_cartridgeitems_printermodels`
                   WHERE `printermodels_id` = '$typeID'";
         $result = $DB->query($query) or die("PB REQUETE ".$query);

         if ($DB->numrows($result)>0) {
            $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query);
            $printed = 0;
            $oldnb   = mt_rand(1,$MAX['cartridges_by_printer']);
            $date1   = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28));
            $date2   = time();
            $inter   = round(($date2-$date1)/$oldnb);

            // Add old cartridges
            for ($j=0 ; $j<$oldnb ; $j++) {
               $printed += mt_rand(0,5000);
               $cart->add(array('entities_id'        => $ID_entity,
                                'cartridgeitems_id'  => $ctypeID,
                                'printers_id'        => $printID,
                                'date_in'            => date("Y-m-d",$date1),
                                'date_use'           => date("Y-m-d",$date1+$j*$inter),
                                'date_out'           => date("Y-m-d",$date1+($j+1)*$inter),
                                'pages'              => $printed));
            }

            // Add current cartridges
            $cart->add(array('entities_id'        => $ID_entity,
                             'cartridgeitems_id'  => $ctypeID,
                             'printers_id'        => $printID,
                             'date_in'            => date("Y-m-d",$date1),
                             'date_use'           => date("Y-m-d",$date2)));
         }
      }
   }

   $LAST["computers"] = getMaxItem("glpi_computers");
   $LAST["monitors"]  = getMaxItem("glpi_monitors");
   $LAST["phones"]    = getMaxItem("glpi_phones");


   // Add global peripherals
   $periph = new Peripheral();
   $ci     = new Computer_Item();
   for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) {
      $techID  = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);

      $periphID = $periph->add(toolbox::addslashes_deep(
                               array('entities_id'       => $ID_entity,
                                     'name'              => "periph '$i-$ID_entity",
                                     'serial'            => Toolbox::getRandomString(10),
                                     'otherserial'       => Toolbox::getRandomString(10),
                                     'contact'           => "contact' $i",
                                     'contact_num'       => "num' $i",
                                     'users_id_tech'     => $techID,
                                     'groups_id_tech'    => $gtechID,
                                     'comment'           => "comment' $i",
                                     'brand'             => "brand' $i",
                                     'locations_id'      => $loc,
                                     'phonetypes_id'     => mt_rand(1,$MAX['type_peripherals']),
                                     'phonemodels_id'    => mt_rand(1,$MAX['model_peripherals']),
                                     'manufacturers_id'  => mt_rand(1,$MAX['manufacturer']),
                                     'is_global'         => 1,
                                     'notepad'           => "notes peripheral' $i",
                                     'users_id'          => mt_rand($FIRST['users_normal'],
                                                                    $LAST['users_normal']),
                                     'groups_id'         => mt_rand($FIRST["groups"], $LAST["groups"]),
                                     'states_id'         => (mt_rand(0,100)<$percent['state']
                                                               ?mt_rand($FIRST['state'],$LAST['state']):0)
                                 )));

      addDocuments('Peripheral', $periphID);
      addContracts('Peripheral', $periphID);

      // Add trackings
      addTracking('Peripheral', $periphID, $ID_entity);

      // Add reservation
      addReservation('Peripheral', $periphID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Peripheral', $periphID, $ID_entity);

      // Add connections
      $val = mt_rand(1,$MAX['connect_for_peripherals']);
      for ($j=1 ; $j<$val ; $j++) {
         $ci->add(array('itemtype'     => 'Peripheral',
                        'items_id'     => $periphID,
                        'computers_id' => mt_rand($FIRST["computers"],$LAST['computers'])));
      }
   }

   $LAST["peripherals"] = getMaxItem("glpi_peripherals");

   $FIRST["software"]   = getMaxItem("glpi_softwares")+1;

   // Ajout logiciels + licences associees a divers PCs
   $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"),
                  array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"),
                  array("Acrobat Reader", "6.0", "7.0", "7.04"),
                  array("Gimp", "2.0", "2.2"),
                  array("InkScape", "0.4"));
   $soft       = new Software();
   $softvers   = new SoftwareVersion();
   $softlic    = new SoftwareLicense();
   $csv        = new Computer_SoftwareVersion();
   $csl        = new Computer_SoftwareLicense();
   for ($i=0 ; $i<$MAX['software'] ; $i++) {

      if (isset($items[$i])) {
         $name = $items[$i][0];
      } else {
         $name = "software '$i";
      }

      $loc       = mt_rand(1,$MAX['locations']);
      $techID    = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']);
      $gtechID   = mt_rand($FIRST["techgroups"],$LAST["techgroups"]);
      $recursive = mt_rand(0,1);

      $softID = $soft->add(toolbox::addslashes_deep(
                           array('entities_id'           => $ID_entity,
                                 'is_recursive'          => $recursive,
                                 'name'                  => $name,
                                 'comment'               => "comment '$i",
                                 'locations_id'          => $loc,
                                 'users_id_tech'         => $techID,
                                 'groups_id_tech'        => $gtechID,
                                 'manufacturers_id'      => mt_rand(1,$MAX['manufacturer']),
                                 'notepad'               => "notes software '$i",
                                 'users_id'              => mt_rand($FIRST['users_admin'],
                                                                    $LAST['users_admin']),
                                 'groups_id'             => mt_rand($FIRST["groups"], $LAST["groups"]),
                                 'is_helpdesk_visible'   => 1,
                                 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory'])
                              )));

      addDocuments('Software', $softID);
      addContracts('Software', $softID);

      // Add trackings
      addTracking('Software', $softID, $ID_entity);

      // AJOUT INFOCOMS
      addInfocoms('Software', $softID, $ID_entity);

      // Add versions
      $FIRST["version"] = getMaxItem("glpi_softwareversions")+1;

      if (isset($items[$i])) {
         $val2 = count($items[$i]);
      } else {
         $val2 = mt_rand(1,$MAX['softwareversions']+1);
      }

      for ($j=1 ; $j<=$val2 ; $j++) {
         if (isset($items[$i])) {
            $version = $items[$i][mt_rand(1,count($items[$i])-1)];
         } else {
            $version = "$j.0";
         }
         $os = mt_rand(1,$MAX['os']);

         $versID = $softvers->add(toolbox::addslashes_deep(
                                  array('entities_id'          => $ID_entity,
                                        'is_recursive'         => $recursive,
                                        'softwares_id'         => $softID,
                                        'name'                 => $version,
                                        'comment'              => "comment '$version",
                                        'states_id'            => (mt_rand(0,100)<$percent['state']
                                                                     ?mt_rand($FIRST['state'],$LAST['state']):0),
                                        'operatingsystems_id'  => $os)));

         $val3    = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall']));
         $comp_id = mt_rand($FIRST["computers"], $LAST['computers']);

         for ($k=0 ; $k<$val3 ; $k++) {
            $comp_id++;
            if ($comp_id>$LAST["computers"]) {
               $comp_id = $FIRST["computers"];
            }
            $csv->add(array('computers_id'        => $comp_id,
                            'softwareversions_id' => $versID));
         }
      }
      $LAST["version"] = getMaxItem("glpi_softwareversions");


      // Add licenses
      $val2 = mt_rand(1,$MAX['softwarelicenses']);

      for ($j=0 ; $j<$val2 ; $j++) {
         $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]);
         $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]);

         $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall']));

         $licID = $softlic->add(toolbox::addslashes_deep(
                                array('entities_id'               => $ID_entity,
                                      'is_recursive'              => $recursive,
                                      'softwares_id'              => $softID,
                                      'number'                    => $nbused,
                                      'softwarelicensetypes_id'   => mt_rand(1,$MAX['licensetype']),
                                      'name'                      => "license '$j",
                                      'serial'                    => "serial $j",
                                      'otherserial'               => "otherserial $j",
                                      'comment'                   => "comment license '$j",
                                      'softwareversions_id_buy'   => $softwareversions_id_buy,
                                      'softwareversions_id_use'   => $softwareversions_id_use)));

         $comp_id = mt_rand($FIRST["computers"], $LAST['computers']);

         for ($k=0 ; $k<$nbused ; $k++) {
            $comp_id++;
            if ($comp_id>$LAST["computers"]) {
               $comp_id = $FIRST["computers"];
            }
            $csl->add(array('computers_id'          => $comp_id,
                            'softwarelicenses_id'   => $licID));
         }
      }
   }
   $LAST["software"] = getMaxItem("glpi_softwares");
}
Beispiel #10
0
 /**
  * Custom add method to add an invoice. Needs a contact for each invocie else 
  * do not add the invoice
  * @param $evtcl -- Object  
  */
 function addInvoice(EventControler $evtcl)
 {
     $_SESSION['in_page_message'] = '';
     $rec_value = $evtcl->recurrent;
     $add_invoice = false;
     $do_contact = new Contact();
     $concat_name_in_address = '';
     if ($evtcl->fields["due_date"] == '') {
         $this->due_date = date('Y-m-d');
     } else {
         $this->due_date = $evtcl->fields["due_date"];
     }
     if ($evtcl->idcontact) {
         $idcontact = $evtcl->idcontact;
         $add_invoice = true;
         $do_contact->getId($idcontact);
     } else {
         $cont_name = $evtcl->contact;
         if ($cont_name != '') {
             $do_Contact_View = new ContactView();
             $do_contact->addNew();
             $do_contact->firstname = $cont_name;
             $do_contact->iduser = $_SESSION['do_User']->iduser;
             $do_contact->add();
             $idcontact = $do_contact->getPrimaryKeyValue();
             $do_Contact_View->setUser($_SESSION['do_User']->iduser);
             $do_contact->getId($idcontact);
             $concat_name_in_address = $do_contact->firstname;
             $do_Contact_View->addFromContact($do_contact);
             $do_Contact_View->updateFromContact($do_contact);
             if ($idcontact) {
                 $add_invoice = true;
                 $do_cont_addr = new ContactAddress();
                 $do_cont_addr->addNew();
                 $do_cont_addr->idcontact = $idcontact;
                 $do_cont_addr->address = $evtcl->fields["invoice_address"];
                 $do_cont_addr->address_type = 'Work';
                 if (strlen($evtcl->fields["invoice_address"]) > 0) {
                     $do_cont_addr->add();
                 }
             }
         }
     }
     if ($add_invoice) {
         // Keep the idcontact in case there is an idcompany
         if ($do_contact->idcompany != '' && !empty($do_contact->idcompany)) {
             $this->idcompany = $do_contact->idcompany;
         }
         //$this->num = $this->getUniqueInvoiceNum();
         $this->num = time();
         $this->iduser = $_SESSION['do_User']->iduser;
         $this->idterms = $evtcl->fields["idterms"];
         $this->description = $evtcl->fields["description"];
         $this->discount = $evtcl->fields["discount"];
         $this->tax = $evtcl->fields["tax"];
         $this->datecreated = date("Y-m-d");
         $this->idcontact = $idcontact;
         $this->status = 'Quote';
         $this->invoice_note = $evtcl->fields["invoice_note"];
         $this->invoice_term = $evtcl->fields["invoice_term"];
         if ($concat_name_in_address == '') {
             $this->invoice_address = $evtcl->fields["invoice_address"];
         } else {
             $this->invoice_address = $concat_name_in_address . '<br />' . $evtcl->fields["invoice_address"];
         }
         $this->add();
         $this->idinvoice = $this->getPrimaryKeyValue();
         // If the user set to have the ivoice added as recurrent Invoice then add
         if ($evtcl->setRec == 'Yes') {
             if (!empty($rec_value) && preg_match('/^[0-9]+$/', $rec_value) && $rec_value != 0) {
                 // Add to recurrent
                 $_SESSION['RecurrentInvoice']->addRecurrentInvoice($this->getPrimaryKeyValue(), $evtcl->recurrent, $evtcl->frequency, date("Y-m-d"));
             } else {
                 $_SESSION['in_page_message'] = _("Recurrent Value is not correct.To set as Recurrent edit the invoice and enter numeric value");
             }
         }
     } else {
         $_SESSION['in_page_message'] = _("Invoice could be created. Possible reason Contact Missing.");
         $evtcl->setDisplayNext(new Display('invoices.php'));
     }
 }
Beispiel #11
0
        } catch (Exception $e) {
            $disp = new Display("user_login.php");
            $disp->addParam("message", "Error with your user record, please sign-in again");
            //$disp->addParam("entry", $_SERVER['REQUEST_URI']);
            $_SESSION['entry'] = $_SERVER['REQUEST_URI'];
            header("Location: /" . $disp->getUrl());
        }
    }
}
if ($_SESSION['hcard_idcontact'] != '') {
    $do_add_cont = new Contact();
    $do_add_cont->addNew();
    $do_add_cont->firstname = $_SESSION['do_contact']->firstname;
    $do_add_cont->lastname = $_SESSION['do_contact']->lastname;
    $do_add_cont->iduser = $_SESSION['do_User']->iduser;
    $do_add_cont->add();
    $idcontact_inserted = $do_add_cont->getPrimaryKeyValue();
    $ContactPhone = $_SESSION['do_contact']->getChildContactPhone();
    $ContactPhoneAdd = new ContactPhone();
    if ($ContactPhone->getNumRows()) {
        while ($ContactPhone->next()) {
            $ContactPhoneAdd->addNew();
            $ContactPhoneAdd->idcontact = $idcontact_inserted;
            $ContactPhoneAdd->phone_type = $ContactPhone->phone_type;
            $ContactPhoneAdd->phone_number = $ContactPhone->phone_number;
            $ContactPhoneAdd->add();
        }
    }
    $ContactEmail = $_SESSION['do_contact']->getChildContactEmail();
    $ContactEmailAdd = new ContactEmail();
    if ($ContactEmail->getNumRows()) {
 function eventImportAccount(EventControler $evtcl)
 {
     $msg = "";
     $uploaded_file = $_FILES['fields']['name']['import_account'];
     $target_path = 'files/' . $uploaded_file;
     if (!move_uploaded_file($_FILES['fields']['tmp_name']['import_account'], $target_path)) {
         $msg = "There was an error uploading the file, please try again!";
     } else {
         chmod($target_path, 0755);
         if (file_exists($target_path)) {
             //$xml = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/".$target_path);
             $str_xml = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/" . $target_path);
             $str_xml = preg_replace('/[^(\\x20-\\x7F)]*/', '', $str_xml);
             $xml = simplexml_load_string($str_xml);
             echo '<pre>';
             print_r($xml);
             echo '</pre>';
             die;
             if ($xml !== FALSE) {
                 $c_cnt = count($xml->contact);
                 if ($c_cnt) {
                     for ($i = 0; $i < $c_cnt; $i++) {
                         $do_contact = new Contact();
                         $contact = $xml->contact[$i];
                         $do_contact->firstname = $contact->firstname;
                         $do_contact->lastname = $contact->lastname;
                         $do_contact->position = $contact->position;
                         $do_contact->company = $contact->company;
                         $do_contact->idcompany = $contact->idcompany;
                         $do_contact->iduser = $_SESSION['do_User']->iduser;
                         $do_contact->picture = $contact->picture;
                         $do_contact->summary = $contact->summary;
                         $do_contact->birthday = $contact->birthday;
                         $do_contact->portal_code = $contact->portal_code;
                         $do_contact->fb_userid = $contact->fb_userid;
                         $do_contact->tw_user_id = $contact->tw_user_id;
                         $do_contact->email_optout = $contact->email_optout;
                         $do_contact->add();
                         $lastInsertedContId = $do_contact->getPrimaryKeyValue();
                         /**
                          *Contact Address	
                          */
                         $ca_cnt = count($contact->contact_address);
                         if ($ca_cnt) {
                             for ($ca_cnt_i = 0; $ca_cnt_i < $ca_cnt; $ca_cnt_i++) {
                                 $do_contact_address = new ContactAddress();
                                 $contact_address = $contact->contact_address[$ca_cnt_i];
                                 $do_contact_address->city = $contact_address->city;
                                 $do_contact_address->country = $contact_address->country;
                                 $do_contact_address->state = $contact_address->state;
                                 $do_contact_address->street = $contact_address->street;
                                 $do_contact_address->zipcode = $contact_address->zipcode;
                                 $do_contact_address->idcontact = $lastInsertedContId;
                                 $do_contact_address->address = $contact_address->address;
                                 $do_contact_address->address_type = $contact_address->address_type;
                                 $do_contact_address->add();
                                 $do_contact_address->free();
                             }
                         }
                         /**
                          *Contact Email	
                          */
                         $ce_cnt = count($contact->contact_email);
                         if ($ce_cnt) {
                             for ($ce_cnt_i = 0; $ce_cnt_i < $ce_cnt; $ce_cnt_i++) {
                                 $do_contact_email = new ContactEmail();
                                 $contact_email = $contact->contact_email[$ce_cnt_i];
                                 $do_contact_email->idcontact = $lastInsertedContId;
                                 $do_contact_email->email_address = $contact_email->email_address;
                                 $do_contact_email->email_type = $contact_email->email_type;
                                 $do_contact_email->email_isdefault = $contact_email->email_isdefault;
                                 $do_contact_email->add();
                                 $do_contact_email->free();
                             }
                         }
                         /**
                          *Contact Phone 
                          */
                         $cp_cnt = count($contact->contact_phone);
                         if ($cp_cnt) {
                             for ($cp_cnt_i = 0; $cp_cnt_i < $cp_cnt; $cp_cnt_i++) {
                                 $do_contact_phone = new ContactPhone();
                                 $contact_phone = $contact->contact_phone[$cp_cnt_i];
                                 $do_contact_phone->phone_number = $contact_phone->phone_number;
                                 $do_contact_phone->phone_type = $contact_phone->phone_type;
                                 $do_contact_phone->idcontact = $lastInsertedContId;
                                 $do_contact_phone->add();
                                 $do_contact_phone->free();
                             }
                         }
                         /**
                          *Contact Note	
                          */
                         $cn_cnt = count($contact->contact_note);
                         if ($cn_cnt) {
                             for ($cn_cnt_i = 0; $cn_cnt_i < $cn_cnt; $cn_cnt_i++) {
                                 $do_contact_note = new ContactNotes();
                                 $contact_note = $contact->contact_note[$cn_cnt_i];
                                 $do_contact_note->idcontact = $lastInsertedContId;
                                 $do_contact_note->note = $contact_note->note;
                                 $do_contact_note->date_added = $contact_note->date_added;
                                 $do_contact_note->document = $contact_note->document;
                                 $do_contact_note->idcompany = $contact_note->idcompany;
                                 $do_contact_note->iduser = $_SESSION['do_User']->iduser;
                                 $do_contact_note->priority = $contact_note->priority;
                                 $do_contact_note->send_email = $contact_note->send_email;
                                 $do_contact_note->hours_work = $contact_note->hours_work;
                                 $do_contact_note->note_visibility = $contact_note->note_visibility;
                                 $do_contact_note->type = $contact_note->type;
                                 $do_contact_note->add();
                                 $do_contact_note->free();
                             }
                         }
                         /**
                          *Contact Tag	
                          */
                         $ctag_cnt = count($contact->contact_tag);
                         if ($ctag_cnt) {
                             for ($ctag_cnt_i = 0; $ctag_cnt_i < $ctag_cnt; $ctag_cnt_i++) {
                                 $do_tag = new Tag();
                                 $contact_tag = $contact->contact_tag[$ctag_cnt_i];
                                 $do_tag->tag_name = $contact_tag->tag_name;
                                 $do_tag->iduser = $_SESSION['do_User']->iduser;
                                 $do_tag->reference_type = $contact_tag->reference_type;
                                 $do_tag->idreference = $lastInsertedContId;
                                 $do_tag->date_added = $contact_tag->date_added;
                                 $do_tag->add();
                                 $do_tag->free();
                             }
                         }
                         /**
                          *Contact tasks which are not associated with Project	
                          */
                         //Contact tasks which are not associated with Project
                         $ctwop_cnt = count($contact->contact_task_without_project);
                         if ($ctwop_cnt) {
                             for ($ctwop_cnt_i = 0; $ctwop_cnt_i < $ctwop_cnt; $ctwop_cnt_i++) {
                                 $do_task = new Task();
                                 $contact_task_wo_p = $contact->contact_task_without_project[$ctwop_cnt_i];
                                 $do_task->task_description = $contact_task_wo_p->task_description;
                                 $do_task->due_date = $contact_task_wo_p->due_date;
                                 $do_task->category = $contact_task_wo_p->category;
                                 $do_task->iduser = $_SESSION['do_User']->iduser;
                                 $do_task->due_date_dateformat = $contact_task_wo_p->due_date_dateformat;
                                 $do_task->status = $contact_task_wo_p->status;
                                 $do_task->date_completed = $contact_task_wo_p->date_completed;
                                 $do_task->idcontact = $lastInsertedContId;
                                 $do_task->from_note = $contact_task_wo_p->from_note;
                                 $do_task->is_sp_date_set = $contact_task_wo_p->is_sp_date_set;
                                 $do_task->task_category = $contact_task_wo_p->task_category;
                                 $do_task->add();
                                 $do_task->free();
                             }
                         }
                         /**
                          *Contact tasks which are associated with Project	
                          */
                         $arr_prj = array();
                         $cont_task_with_prj_cnt = count($contact->contact_task_with_project);
                         if ($cont_task_with_prj_cnt) {
                             for ($i = 0; $i < $cont_task_with_prj_cnt; $i++) {
                                 $do_project = new Project();
                                 $project = $contact->contact_task_with_project[$i];
                                 $do_project->iduser = $_SESSION['do_User']->iduser;
                                 $do_project->name = $project->name;
                                 $do_project->end_date_dateformat = $project->end_date_dateformat;
                                 $do_project->idcompany = $project->idcompany;
                                 $do_project->status = $project->status;
                                 $do_project->effort_estimated_hrs = $project->effort_estimated_hrs;
                                 $do_project->is_public = $project->is_public;
                                 $do_project->add();
                                 $lastInsertedPrjId = $do_project->getPrimaryKeyValue();
                                 //$arr_prj[$lastInsertedPrjId] = $project->idproject;
                                 $pt_cnt = count($project->project_task);
                                 if ($pt_cnt) {
                                     for ($pt_cnt_i = 0; $pt_cnt_i < $pt_cnt; $pt_cnt_i++) {
                                         $do_task = new Task();
                                         $project_task = $project->project_task[$pt_cnt_i];
                                         $do_task->task_description = $project_task->task_description;
                                         $do_task->due_date = $project_task->due_date;
                                         $do_task->category = $project_task->category;
                                         $do_task->iduser = $_SESSION['do_User']->iduser;
                                         $do_task->due_date_dateformat = $project_task->due_date_dateformat;
                                         $do_task->status = $project_task->status;
                                         $do_task->date_completed = $project_task->date_completed;
                                         $do_task->idcontact = $lastInsertedContId;
                                         $do_task->from_note = $project_task->from_note;
                                         $do_task->is_sp_date_set = $project_task->is_sp_date_set;
                                         $do_task->task_category = $project_task->task_category;
                                         $do_task->add();
                                         $lastInsertedTaskId = $do_task->getPrimaryKeyValue();
                                         $do_project_task = new ProjectTask();
                                         $do_project_task->idtask = $lastInsertedTaskId;
                                         $do_project_task->idproject = $lastInsertedPrjId;
                                         $do_project_task->progress = $project_task->progress;
                                         $do_project_task->drop_box_code = $project_task->drop_box_code;
                                         $do_project_task->priority = $project_task->priority;
                                         $do_project_task->hrs_work_expected = $project_task->hrs_work_expected;
                                         $do_project_task->add();
                                         $lastInsertedPrjTaskId = $do_project_task->getPrimaryKeyValue();
                                         $pd_cnt = count($project_task->project_discuss);
                                         if ($pd_cnt) {
                                             for ($i = 0; $i < $pd_cnt; $i++) {
                                                 $do_project_discuss = new ProjectDiscuss();
                                                 $project_discuss = $project_task->project_discuss[$i];
                                                 $do_project_discuss->idproject_task = $lastInsertedPrjTaskId;
                                                 $do_project_discuss->idtask = $lastInsertedTaskId;
                                                 $do_project_discuss->idproject = $lastInsertedPrjId;
                                                 $do_project_discuss->discuss = $project_discuss->discuss;
                                                 $do_project_discuss->date_added = $project_discuss->date_added;
                                                 $do_project_discuss->document = $project_discuss->document;
                                                 $do_project_discuss->iduser = $_SESSION['do_User']->iduser;
                                                 $do_project_discuss->drop_box_sender = $project_discuss->drop_box_sender;
                                                 $do_project_discuss->priority = $project_discuss->priority;
                                                 $do_project_discuss->hours_work = $project_discuss->hours_work;
                                                 $do_project_discuss->discuss_edit_access = $project_discuss->discuss_edit_access;
                                                 $do_project_discuss->type = $project_discuss->type;
                                                 $do_project_discuss->add();
                                                 $do_project_discuss->free();
                                             }
                                         }
                                         $do_project_task->free();
                                         $do_task->free();
                                     }
                                 }
                                 $do_project->free();
                             }
                         }
                         /**
                          *Invoice import
                          */
                         $msg_inv = "";
                         $inv_cnt = count($contact->invoice);
                         if ($inv_cnt) {
                             for ($inv_cnt_i = 0; $inv_cnt_i < $inv_cnt; $inv_cnt_i++) {
                                 $do_invoice = new Invoice();
                                 $invoice = $contact->invoice[$inv_cnt_i];
                                 $do_invoice->num = $invoice->num;
                                 $do_invoice->iduser = $_SESSION['do_User']->iduser;
                                 $do_invoice->description = $invoice->description;
                                 $do_invoice->amount = $invoice->amount;
                                 $do_invoice->datepaid = $invoice->datepaid;
                                 $do_invoice->datecreated = $invoice->datecreated;
                                 $do_invoice->status = $invoice->status;
                                 $do_invoice->discount = $invoice->discount;
                                 $do_invoice->idcontact = $lastInsertedContId;
                                 $do_invoice->due_date = $invoice->due_date;
                                 $do_invoice->invoice_address = $invoice->invoice_address;
                                 $do_invoice->invoice_term = $invoice->invoice_term;
                                 $do_invoice->invoice_note = $invoice->invoice_note;
                                 $do_invoice->sub_total = $invoice->sub_total;
                                 $do_invoice->net_total = $invoice->net_total;
                                 $do_invoice->amt_due = $invoice->amt_due;
                                 $do_invoice->idcompany = $invoice->idcompany;
                                 $do_invoice->tax = $invoice->tax;
                                 $do_invoice->set_delete = $invoice->set_delete;
                                 $do_invoice->total_discounted_amt = $invoice->total_discounted_amt;
                                 $do_invoice->total_taxed_amount = $invoice->total_taxed_amount;
                                 $do_invoice->add();
                                 $lastInsertedInvoiceId = $do_invoice->getPrimaryKeyValue();
                                 $invline_cnt = count($invoice->invoiceline);
                                 if ($invline_cnt) {
                                     for ($invline_cnt_i = 0; $invline_cnt_i < $invline_cnt; $invline_cnt_i++) {
                                         $do_invoiceline = new InvoiceLine();
                                         $invoiceline = $invoice->invoiceline[$invline_cnt_i];
                                         $do_invoiceline->idinvoice = $lastInsertedInvoiceId;
                                         $do_invoiceline->description = $invoiceline->description;
                                         $do_invoiceline->price = $invoiceline->price;
                                         $do_invoiceline->qty = $invoiceline->qty;
                                         $do_invoiceline->total = $invoiceline->total;
                                         $do_invoiceline->item = $invoiceline->item;
                                         $do_invoiceline->line_tax = $invoiceline->line_tax;
                                         $do_invoiceline->discounted_amount = $invoiceline->discounted_amount;
                                         $do_invoiceline->taxed_amount = $invoiceline->taxed_amount;
                                         $do_invoiceline->add();
                                         $do_invoiceline->free();
                                     }
                                 }
                                 //invoiceline import ends
                                 // recurrentinvoice
                                 $recinv_cnt = count($invoice->recurrentinvoice);
                                 if ($recinv_cnt) {
                                     for ($recinv_cnt_i = 0; $recinv_cnt_i < $recinv_cnt; $recinv_cnt_i++) {
                                         $do_recurrentinvoice = new RecurrentInvoice();
                                         $recurrentinvoice = $invoice->recurrentinvoice[$recinv_cnt_i];
                                         $do_recurrentinvoice->iduser = $_SESSION['do_User']->iduser;
                                         $do_recurrentinvoice->idinvoice = $lastInsertedInvoiceId;
                                         $do_recurrentinvoice->nextdate = $recurrentinvoice->nextdate;
                                         $do_recurrentinvoice->recurrence = $recurrentinvoice->recurrence;
                                         $do_recurrentinvoice->recurrencetype = $recurrentinvoice->recurrencetype;
                                         $do_recurrentinvoice->add();
                                         $do_recurrentinvoice->free();
                                     }
                                 }
                                 //recurrentinvoice import ends
                                 // Payment Log import
                                 $paymentlog_cnt = count($invoice->paymentlog);
                                 if ($paymentlog_cnt) {
                                     for ($paymentlog_cnt_i = 0; $paymentlog_cnt_i < $paymentlog_cnt; $paymentlog_cnt_i++) {
                                         $do_paymentlog = new PaymentLog();
                                         $paymentlog = $invoice->paymentlog[$paymentlog_cnt_i];
                                         $do_paymentlog->timestamp = $paymentlog->timestamp;
                                         $do_paymentlog->idinvoice = $lastInsertedInvoiceId;
                                         $do_paymentlog->amount = $paymentlog->amount;
                                         $do_paymentlog->payment_type = $paymentlog->payment_type;
                                         $do_paymentlog->ref_num = $paymentlog->ref_num;
                                         $do_paymentlog->date_added = $paymentlog->date_added;
                                         $do_paymentlog->add();
                                         $lastInsertedPaymentLogId = $do_paymentlog->getPrimaryKeyValue();
                                         //payment_invoice : Payment Invoice import
                                         $paymentinv_cnt = count($paymentlog->payment_invoice);
                                         if ($paymentinv_cnt) {
                                             for ($paymentinv_cnt_i = 0; $paymentinv_cnt_i < $paymentinv_cnt; $paymentinv_cnt_i++) {
                                                 $do_payment_invoice = new PaymentInvoice();
                                                 $paymentinvoice = $paymentlog->payment_invoice[$paymentinv_cnt_i];
                                                 $do_payment_invoice->idpayment = $lastInsertedPaymentLogId;
                                                 $do_payment_invoice->idinvoice = $lastInsertedInvoiceId;
                                                 $do_payment_invoice->amount = $paymentinvoice->amount;
                                                 $do_payment_invoice->add();
                                                 $do_payment_invoice->free();
                                             }
                                         }
                                         // payment_invoice import ends
                                         //paymentlog_extra_amount import
                                         $paymentlog_ext_amt_cnt = count($paymentlog->paymentlog_extra_amount);
                                         if ($paymentlog_ext_amt_cnt) {
                                             for ($paymentlog_ext_amt_cnt_i = 0; $paymentlog_ext_amt_cnt_i < $paymentlog_ext_amt_cnt; $paymentlog_ext_amt_cnt_i++) {
                                                 $paymentlog_extra_amount = $paymentlog->paymentlog_extra_amount[$paymentlog_ext_amt_cnt_i];
                                                 $q = new sqlQuery($GLOBALS['conx']);
                                                 $query = "INSERT INTO paymentlog_extra_amount (`idpaymentlog`,`extra_amt`,`iduser`)\n            VALUES (" . $lastInsertedPaymentLogId . "," . $paymentlog_extra_amount->extra_amt . "," . $_SESSION['do_User']->iduser . ")\n            ";
                                                 $q->query($query);
                                                 $q->free();
                                             }
                                         }
                                         // paymentlog_extra_amount import ends
                                         $do_paymentlog->free();
                                     }
                                 }
                                 //Payment Log import ends
                                 $msg_inv = ", Invoices";
                                 $do_invoice->free();
                             }
                         }
                         // Invoice import ends
                         /************************************************************************************************************************/
                         $do_contact->free();
                     }
                     $msg = "Your Contacts" . $msg_inv;
                 }
                 /**
                  *Company insert
                  */
                 $compani_id = array();
                 $lastInsertedCompani_id = array();
                 $companies_cnt = count($xml->companies);
                 if ($companies_cnt) {
                     for ($i = 0; $i < $companies_cnt; $i++) {
                         $do_company = new Company();
                         $company = $xml->companies[$i];
                         array_push($compani_id, "{$company->idcompany}");
                         // $do_company->idcompany=$company->idcompany;
                         $do_company->name = $company->name;
                         $do_company->iduser = $_SESSION['do_User']->iduser;
                         $do_company->add();
                         array_push($lastInsertedCompani_id, $do_company->getPrimaryKeyValue());
                         $do_company->free();
                     }
                 }
                 //tasks which are neither associated with Contact nor with project
                 $task_wop_cnt = count($xml->task_without_project);
                 if ($task_wop_cnt) {
                     for ($i = 0; $i < $task_wop_cnt; $i++) {
                         $do_task = new Task();
                         $task_wop = $xml->task_without_project[$i];
                         $do_task->task_description = $task_wop->task_description;
                         $do_task->due_date = $task_wop->due_date;
                         $do_task->category = $task_wop->category;
                         $do_task->iduser = $_SESSION['do_User']->iduser;
                         $do_task->due_date_dateformat = $task_wop->due_date_dateformat;
                         $do_task->status = $task_wop->status;
                         $do_task->date_completed = $task_wop->date_completed;
                         $do_task->idcontact = $task_wop->idcontact;
                         //it would be 0 since not associated with contact.
                         $do_task->from_note = $task_wop->from_note;
                         $do_task->is_sp_date_set = $task_wop->is_sp_date_set;
                         $do_task->task_category = $task_wop->task_category;
                         $do_task->add();
                         $do_task->free();
                     }
                     $msg .= ", Tasks";
                 }
                 //tasks which are associated with Project
                 $prj_cnt = count($xml->project);
                 if ($prj_cnt) {
                     for ($i = 0; $i < $prj_cnt; $i++) {
                         $do_project = new Project();
                         $project = $xml->project[$i];
                         $do_project->iduser = $_SESSION['do_User']->iduser;
                         $do_project->name = $project->name;
                         $do_project->end_date_dateformat = $project->end_date_dateformat;
                         $do_project->idcompany = $project->idcompany;
                         $do_project->status = $project->status;
                         $do_project->effort_estimated_hrs = $project->effort_estimated_hrs;
                         $do_project->is_public = $project->is_public;
                         $do_project->add();
                         $lastInsertedPrjId = $do_project->getPrimaryKeyValue();
                         $pt_cnt = count($project->project_task);
                         if ($pt_cnt) {
                             for ($pt_cnt_i = 0; $pt_cnt_i < $pt_cnt; $pt_cnt_i++) {
                                 $do_task = new Task();
                                 $project_task = $project->project_task[$pt_cnt_i];
                                 $do_task->task_description = $project_task->task_description;
                                 $do_task->due_date = $project_task->due_date;
                                 $do_task->category = $project_task->category;
                                 $do_task->iduser = $_SESSION['do_User']->iduser;
                                 $do_task->due_date_dateformat = $project_task->due_date_dateformat;
                                 $do_task->status = $project_task->status;
                                 $do_task->date_completed = $project_task->date_completed;
                                 $do_task->idcontact = $project_task->idcontact;
                                 $do_task->from_note = $project_task->from_note;
                                 $do_task->is_sp_date_set = $project_task->is_sp_date_set;
                                 $do_task->task_category = $project_task->task_category;
                                 $do_task->add();
                                 $lastInsertedTskId = $do_task->getPrimaryKeyValue();
                                 $q = new sqlQuery($GLOBALS['conx']);
                                 if ($project_task->progress == '') {
                                     $project_task_progress = 0;
                                 } else {
                                     $project_task_progress = $project_task->progress;
                                 }
                                 $sql = "INSERT INTO \n\t\t\tproject_task (idtask, idproject, progress,drop_box_code,priority,hrs_work_expected) \n\t\t\tVALUES ({$lastInsertedTskId},{$lastInsertedPrjId},{$project_task_progress},{$project_task->drop_box_code},{$project_task->priority},{$project_task->hrs_work_expected})";
                                 echo $sql;
                                 echo "<br>";
                                 $q->query($sql);
                                 $lastInsertedPrjTaskId = $q->getInsertId('project_task', 'idproject_task');
                                 $pd_cnt = count($project_task->project_discuss);
                                 if ($pd_cnt) {
                                     for ($pd_cnt_i = 0; $pd_cnt_i < $pd_cnt; $pd_cnt_i++) {
                                         $do_project_discuss = new ProjectDiscuss();
                                         $project_discuss = $project_task->project_discuss[$pd_cnt_i];
                                         $do_project_discuss->idproject_task = $lastInsertedPrjTaskId;
                                         $do_project_discuss->idtask = $lastInsertedTskId;
                                         $do_project_discuss->idproject = $lastInsertedPrjId;
                                         $do_project_discuss->discuss = $project_discuss->discuss;
                                         $do_project_discuss->date_added = $project_discuss->date_added;
                                         $do_project_discuss->document = $project_discuss->document;
                                         $do_project_discuss->iduser = $_SESSION['do_User']->iduser;
                                         $do_project_discuss->drop_box_sender = $project_discuss->drop_box_sender;
                                         $do_project_discuss->priority = $project_discuss->priority;
                                         $do_project_discuss->hours_work = $project_discuss->hours_work;
                                         $do_project_discuss->discuss_edit_access = $project_discuss->discuss_edit_access;
                                         $do_project_discuss->type = $project_discuss->type;
                                         $do_project_discuss->add();
                                         $do_project_discuss->free();
                                     }
                                 }
                                 // $do_project_task->free();
                                 $do_task->free();
                             }
                         }
                         $do_project->free();
                     }
                     $compani_id_cnt = count($compani_id);
                     if ($compani_id_cnt) {
                         $j = 0;
                         foreach ($compani_id as $cmp_id) {
                             $q = new sqlQuery($GLOBALS['conx']);
                             $sql = "UPDATE  contact SET idcompany ={$lastInsertedCompani_id[$j]}  WHERE  iduser={$_SESSION['do_User']->iduser} AND idcompany ={$cmp_id}";
                             $q->query($sql);
                             $sql1 = "UPDATE  invoice SET idcompany ={$lastInsertedCompani_id[$j]}  WHERE  iduser={$_SESSION['do_User']->iduser} AND idcompany ={$cmp_id}";
                             $q->query($sql1);
                             $sql2 = "UPDATE  project SET idcompany ={$lastInsertedCompani_id[$j]}  WHERE  iduser={$_SESSION['do_User']->iduser} AND idcompany ={$cmp_id}";
                             $q->query($sql2);
                             $q->free();
                             $j++;
                         }
                     }
                     $do_create_usrtbl = new ContactView();
                     $do_create_usrtbl->rebuildContactUserTable($_SESSION['do_User']->iduser);
                     $msg .= " and Projects have been imported successfully.";
                 }
             } else {
                 $msg = "Sorry! The data could not be imported.";
             }
         } else {
             $msg = "Sorry! Could not find the uploaded file.";
         }
     }
     $_SESSION['in_page_message'] = $msg;
 }
Beispiel #13
0
 /**
  * Method adding user as Contact
  * @param $firstname -- STRING
  * @param $lastname -- STRING
  * @param $company -- STRING
  * @param $email -- STRING
  * @param $iduser -- INT
  * FIXME May be no need to rebuilt the contact view but to enter an entry which is faster
  */
 function addUserAsContact($firstname, $lastname, $company, $email, $iduser)
 {
     $idcompany = "";
     if ($company != "") {
         $do_company = new Company();
         $idcompany = $do_company->addNewCompany($company, $iduser);
     }
     $do_contact = new Contact();
     $do_contact->firstname = $firstname;
     $do_contact->lastname = $lastname;
     $do_contact->iduser = $iduser;
     $do_contact->idcompany = $idcompany;
     $do_contact->company = $company;
     $do_contact->add();
     $do_contact->addEmail($email, 'Home');
     $lastInsertedContId = $do_contact->getPrimaryKeyValue();
     //$this->setRegistry(false);
     $this->getId($iduser);
     $this->idcontact = $lastInsertedContId;
     $this->update();
     $contact_view = new ContactView();
     $contact_view->setUser($iduser);
     //$this->setRegistry(false);
     $contact_view->rebuildContactUserTable();
 }
 protected function importContacts()
 {
     $this->truncateTables(array('contact', 'contact_lang', 'contact_shop'));
     $handle = $this->openCsvFile('contacts.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('Contact', $this->contacts_fields, $line);
         if (!isset($fields['id'])) {
             $contact = new Contact($line[0]);
             $contact->id = $line[0];
         } else {
             $contact = new Contact($fields['id']);
         }
         foreach ($fields as $key => $field) {
             if ($key == 'name' || $key == 'description') {
                 $contact->{$key} = $this->multilFild($field);
             } else {
                 $contact->{$key} = $field;
             }
         }
         $contact->force_id = true;
         if (!$res) {
             $res = $contact->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }
Beispiel #15
0
/**
 * @author Paul Heaney
 * @todo TODO document this function
*/
function ldap_storeDetails($password, $id = 0, $user = TRUE, $populateOnly = FALSE, &$ldap_conn, $user_attributes)
{
    global $CONFIG;
    $toReturn = false;
    if ($populateOnly) {
        $user_bind = true;
    } else {
        // Authentocate
        $user_bind = @ldap_bind($ldap_conn, $_SESSION['ldap_user_dn'], $password);
    }
    if (!$user_bind) {
        // Auth failed
        debug_log("LDAP Invalid credentials {$_SESSION['ldap_user_dn']}", TRUE);
        $toReturn = false;
    } else {
        // Sucessfull
        debug_log("LDAP Valid Credentials", TRUE);
        $usertype = LDAP_INVALID_USER;
        if ($CONFIG['ldap_grponuser']) {
            if (is_array($user_attributes[$CONFIG['ldap_grpattributeuser']])) {
                // Group stored on user
                foreach ($user_attributes[$CONFIG['ldap_grpattributeuser']] as $group) {
                    if ($user) {
                        // User/Staff
                        // NOTE: we dont have to check about overwriting ADMIN type as we break
                        if (strtolower($group) == strtolower($CONFIG['ldap_admin_group'])) {
                            $usertype = LDAP_USERTYPE_ADMIN;
                            break;
                        } elseif (strtolower($group) == strtolower($CONFIG['ldap_manager_group'])) {
                            $usertype = LDAP_USERTYPE_MANAGER;
                        } elseif (strtolower($group) == strtolower($CONFIG['ldap_user_group'])) {
                            if ($usertype != LDAP_USERTYPE_MANAGER) {
                                $usertype = LDAP_USERTYPE_USER;
                            }
                        }
                    } else {
                        //Customer
                        if (strtolower($group) == strtolower($CONFIG['ldap_customer_group'])) {
                            $usertype = LDAP_USERTYPE_CUSTOMER;
                            break;
                        }
                    }
                }
            }
        } else {
            ldap_close($ldap_conn);
            $ldap_conn = ldapOpen();
            // Need to get an admin thread
            if ($CONFIG['ldap_grpfulldn']) {
                $filter = "(&(objectClass={$CONFIG['ldap_grpobjecttype']})({$CONFIG['ldap_grpattributegrp']}={$_SESSION['ldap_user_dn']}))";
            } else {
                $filter = "(&(objectClass={$CONFIG['ldap_grpobjecttype']})({$CONFIG['ldap_grpattributegrp']}={$user_attributes[$CONFIG['ldap_userattribute']][0]}))";
            }
            if ($user) {
                debug_log("USER: {$filter}", TRUE);
                /*
                 * Locate
                 */
                if (ldap_count_entries($ldap_conn, ldap_search($ldap_conn, $CONFIG['ldap_admin_group'], $filter))) {
                    $usertype = LDAP_USERTYPE_ADMIN;
                    debug_log("ADMIN", TRUE);
                } elseif (ldap_count_entries($ldap_conn, ldap_search($ldap_conn, $CONFIG['ldap_manager_group'], $filter))) {
                    $usertype = LDAP_USERTYPE_MANAGER;
                    debug_log("MANAGER", TRUE);
                } elseif (ldap_count_entries($ldap_conn, ldap_search($ldap_conn, $CONFIG['ldap_user_group'], $filter))) {
                    $usertype = LDAP_USERTYPE_USER;
                    debug_log("USER", TRUE);
                } else {
                    debug_log("INVALID USER", TRUE);
                }
            } else {
                // get back customer group
                $result = ldap_search($ldap_conn, $CONFIG['ldap_customer_group'], $filter);
                if (ldap_count_entries($ldap_conn, $result)) {
                    $usertype = LDAP_USERTYPE_CUSTOMER;
                    debug_log("CUSTOMER", TRUE);
                } else {
                    debug_log("INVALID CUSTOMER", TRUE);
                }
            }
        }
        if ($usertype != LDAP_INVALID_USER and $user) {
            // get attributes
            $user = new User();
            $user->username = $user_attributes[$CONFIG['ldap_userattribute']][0];
            if ($CONFIG['ldap_cache_passwords']) {
                $user->password = $password;
            }
            $user->realname = $user_attributes[$CONFIG['ldap_realname']][0];
            $user->jobtitle = $user_attributes[$CONFIG['ldap_jobtitle']][0];
            $user->email = $user_attributes[$CONFIG['ldap_email']][0];
            $user->phone = $user_attributes[$CONFIG['ldap_telephone']][0];
            $user->mobile = $user_attributes[$CONFIG['ldap_mobile']][0];
            $user->fax = $user_attributes[$CONFIG['ldap_fax']][0];
            $user->message = $user_attributes[$CONFIG['ldap_description']][0];
            $user->holiday_entitlement = $CONFIG['default_entitlement'];
            $user->source = 'ldap';
            // TODO FIXME this doesn't take into account custom roles'
            switch ($usertype) {
                case LDAP_USERTYPE_ADMIN:
                    $user->roleid = 1;
                    break;
                case LDAP_USERTYPE_MANAGER:
                    $user->roleid = 2;
                    break;
                default:
                    $user->roleid = 3;
            }
            if ($id == 0) {
                $user->status = $CONFIG['ldap_default_user_status'];
                $status = $user->add();
            } else {
                // Modify
                $user->id = $id;
                $status = $user->edit();
            }
            if ($status) {
                $toReturn = true;
            } else {
                $toReturn = false;
            }
        } elseif ($usertype == LDAP_USERTYPE_CUSTOMER and !$user) {
            // Contact
            debug_log("Adding contact TYPE {$usertype} USER {$user}", TRUE);
            debug_log("User attributes: " . print_r($user_attributes, TRUE), TRUE);
            $contact = new Contact();
            $contact->username = $user_attributes[$CONFIG['ldap_userattribute']][0];
            if ($CONFIG['ldap_cache_passwords']) {
                $contact->password = $password;
            }
            $contact->surname = $user_attributes[$CONFIG['ldap_surname']][0];
            $contact->forenames = $user_attributes[$CONFIG['ldap_forenames']][0];
            $contact->jobtitle = $user_attributes[$CONFIG['ldap_jobtitle']][0];
            $contact->email = $user_attributes[$CONFIG['ldap_email']][0];
            $contact->phone = $user_attributes[$CONFIG['ldap_telephone']][0];
            $contact->mobile = $user_attributes[$CONFIG['ldap_mobile']][0];
            $contact->fax = $user_attributes[$CONFIG['ldap_fax']][0];
            $contact->siteid = $CONFIG['ldap_default_customer_siteid'];
            $contact->address1 = $user_attributes[$CONFIG['ldap_address1']][0];
            $contact->city = $user_attributes[$CONFIG['ldap_city']][0];
            $contact->county = $user_attributes[$CONFIG['ldap_county']][0];
            $contact->postcode = $user_attributes[$CONFIG['ldap_postcode']][0];
            $contact->courtesytitle = $user_attributes[$CONFIG['ldap_courtesytitle']][0];
            $contact->source = 'ldap';
            if ($id == 0) {
                $status = $contact->add();
            } else {
                debug_log("MODIFY CONTACT {$id}", TRUE);
                $contact->id = $id;
                $status = $contact->edit();
            }
            if ($status) {
                $toReturn = true;
            } else {
                $toReturn = false;
            }
        } else {
            $toReturn = false;
        }
    }
    return $toReturn;
}
Beispiel #16
0
 function insertContact()
 {
     if ($this->contact['ORG']) {
         $id_company = $this->checkCompanyExists($this->contact['ORG']);
         $id_company_flag = $id_company ? true : false;
         $flag = true;
     } else {
         $flag = true;
         $id_company = 0;
         $id_company_flag = true;
     }
     if ($flag) {
         if ($id_company_flag) {
             $new_contact = new Contact();
             $new_contact->firstname = $this->contact['FULLNAME'];
             $new_contact->position = $this->contact['TITLE'];
             if ($this->contact['ORG']) {
                 $company = $this->contact['ORG'];
             } else {
                 $company = "";
             }
             $new_contact->company = $company;
             $new_contact->idcompany = $id_company;
             $new_contact->iduser = $this->iduser;
             $new_contact->birthday = $this->contact['BDAY'];
             $new_contact->picture = $this->contact['PHOTO'];
             $new_contact->add();
             $lastInsertedContId = $new_contact->getPrimaryKeyValue();
         } else {
             $new_company = new Company();
             $new_company->name = $this->contact['ORG'];
             $new_company->iduser = $this->iduser;
             $new_company->add();
             $new_company_id = $new_company->getPrimaryKeyValue();
             $new_contact = new Contact();
             $new_contact->firstname = $this->contact['FULLNAME'];
             $new_contact->position = $this->contact['TITLE'];
             $new_contact->company = $this->contact['ORG'];
             $new_contact->idcompany = $new_company_id;
             $new_contact->iduser = $this->iduser;
             $new_contact->birthday = $this->contact['BDAY'];
             $new_contact->picture = $this->contact['PHOTO'];
             $new_contact->add();
             $lastInsertedContId = $new_contact->getPrimaryKeyValue();
         }
         if ($this->contact['TELL_WORK']) {
             $new_contact->addPhone($this->contact['TELL_WORK'], 'Work');
         }
         if ($this->contact['TELL_HOME']) {
             $new_contact->addPhone($this->contact['TELL_HOME'], 'Home');
         }
         if ($this->contact['TELL_FAX']) {
             $new_contact->addPhone($this->contact['TELL_FAX'], 'Fax');
         }
         if ($this->contact['TELL_CELL']) {
             $new_contact->addPhone($this->contact['TELL_CELL'], 'Mobile');
         }
         if ($this->contact['TELL_OTHER']) {
             $new_contact->addPhone($this->contact['TELL_OTHER'], 'Other');
         }
         if ($this->contact['ADR_WORK']) {
             $new_contact->addAddress($this->contact['ADR_WORK'], 'Work');
         }
         if ($this->contact['ADR_HOME']) {
             $new_contact->addAddress($this->contact['ADR_HOME'], 'Home');
         }
         if ($this->contact['ADR_OTHER']) {
             $new_contact->addAddress($this->contact['ADR_OTHER'], 'Other');
         }
         if ($this->contact['EMAIL_WORK']) {
             $new_contact->addEmail($this->contact['EMAIL_WORK'], 'Work');
         }
         if ($this->contact['EMAIL_HOME']) {
             $new_contact->addEmail($this->contact['EMAIL_HOME'], 'Home');
         }
         if ($this->contact['EMAIL_OTHER']) {
             $new_contact->addEmail($this->contact['EMAIL_OTHER'], 'Other');
         }
         $do_tag = new Tag();
         if ($this->contact['CATEGORIES']) {
             $contact_tag = explode(",", $this->contact['CATEGORIES']);
             $arr_import_tags = explode(",", $_SESSION['import_tag']);
             foreach ($arr_import_tags as $imp_tag) {
                 array_push($contact_tag, $imp_tag);
             }
             foreach ($contact_tag as $tag) {
                 $tag = trim($tag);
                 $do_tag->addTagAssociation($lastInsertedContId, $tag, "contact", $this->iduser);
             }
         } else {
             $arr_import_tags = explode(",", $_SESSION['import_tag']);
             foreach ($arr_import_tags as $tag) {
                 $tag = trim($tag);
                 $do_tag->addTagAssociation($lastInsertedContId, $tag, "contact", $this->iduser);
             }
         }
         $do_cont_view = new ContactView();
         $do_cont_view->addFromContact($new_contact);
         $do_cont_view->updateFromContact($new_contact);
         // Added the method call updateFromContact() so that the child data is updated just after insert
         $do_cont_view->addTag($_SESSION['import_tag'], $new_contact->idcontact);
         // Update the contact view for tags.
         $this->imported = true;
     }
 }
 /**
  * inserting a contact entry into ofuz Database.
  * @param array : contact details
  * @return void
  * @see class : Contact, Company
  */
 function insertContactEntry($entry)
 {
     $id_company = $this->checkCompanyExists($entry['org_name']);
     if ($id_company) {
         $new_contact = new Contact();
         $new_contact->company = $entry['org_name'];
         $new_contact->firstname = $entry['title'];
         $new_contact->idcompany = $id_company;
         $new_contact->iduser = $this->id_user;
         $new_contact->position = $entry['org_title'];
         $new_contact->add();
         $lastInsertedContId = $new_contact->getPrimaryKeyValue();
     } else {
         $new_company = new Company();
         $new_company->name = $entry['org_name'];
         $new_company->iduser = $this->id_user;
         $new_company->add();
         $new_company_id = $new_company->getPrimaryKeyValue();
         $new_contact = new Contact();
         $new_contact->company = $entry['org_name'];
         $new_contact->firstname = $entry['title'];
         $new_contact->idcompany = $new_company_id;
         $new_contact->iduser = $this->id_user;
         $new_contact->position = $entry['org_title'];
         $new_contact->add();
         $lastInsertedContId = $new_contact->getPrimaryKeyValue();
     }
     if ($entry['ph_mobile']) {
         $new_contact->addPhone($entry['ph_mobile'], 'Mobile');
     }
     if ($entry['ph_home']) {
         $new_contact->addPhone($entry['ph_home'], 'Home');
     }
     if ($entry['ph_work']) {
         $new_contact->addPhone($entry['ph_work'], 'Work');
     }
     if ($entry['address_home']) {
         $new_contact->addAddress($entry['address_home'], 'Home');
     }
     if ($entry['address_other']) {
         $new_contact->addAddress($entry['address_other'], 'Other');
     }
     if ($entry['address_work']) {
         $new_contact->addAddress($entry['address_work'], 'Work');
     }
     if ($entry['em_other']) {
         $new_contact->addEmail($entry['em_other'], 'Other');
     }
     if ($entry['em_home']) {
         $new_contact->addEmail($entry['em_home'], 'Home');
     }
     if ($entry['em_work']) {
         $new_contact->addEmail($entry['em_work'], 'Work');
     }
     $q_ins_contact = new sqlQuery($this->getDbCon());
     $sql_ins = "INSERT INTO\n                    google_contact_info(idcontact,iduser,entry_id,entry_link_edit,entry_link_self)\n                    VALUES(" . $lastInsertedContId . "," . $this->id_user . ",'" . $entry['id'] . "','" . $entry['link_edit'] . "','" . $entry['link_self'] . "')\n                  ";
     $q_ins_contact->query($sql_ins);
 }
Beispiel #18
0
include '../inc/includes.php';
Session::checkRight("contact_enterprise", READ);
if (empty($_GET["id"])) {
    $_GET["id"] = -1;
}
$contact = new Contact();
if (isset($_GET['getvcard'])) {
    if ($_GET["id"] < 0) {
        Html::redirect($CFG_GLPI["root_doc"] . "/front/contact.php");
    }
    $contact->check($_GET["id"], READ);
    $contact->generateVcard();
} else {
    if (isset($_POST["add"])) {
        $contact->check(-1, CREATE, $_POST);
        if ($newID = $contact->add($_POST)) {
            Event::log($newID, "contacts", 4, "financial", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
            if ($_SESSION['glpibackcreated']) {
                Html::redirect($contact->getFormURL() . "?id=" . $newID);
            }
        }
        Html::back();
    } else {
        if (isset($_POST["delete"])) {
            $contact->check($_POST["id"], DELETE);
            if ($contact->delete($_POST)) {
                Event::log($_POST["id"], "contacts", 4, "financial", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
            }
            $contact->redirectToList();
        } else {
            if (isset($_POST["restore"])) {
 function add_contact()
 {
     $do_api_contact = new Contact();
     $do_Contact_View = new ContactView();
     $do_api_contact->addNew();
     $do_api_contact->firstname = $this->firstname;
     $do_api_contact->lastname = $this->lastname;
     $do_api_contact->position = $this->position;
     $do_api_contact->iduser = $this->iduser;
     if ($this->tags != '') {
         $tags = explode(",", $this->tags);
     }
     if ($this->firstname == "" && $this->lastname == "") {
         $this->setMessage("610", "First Name OR Last Name is Required");
         return false;
     } elseif (!$this->iduser) {
         $this->setMessage("502", "The User Session is expired");
         return false;
     } elseif ($idcontact = $do_api_contact->duplicateContact($this->iduser, $this->email_work, $this->email_home, $this->email_other)) {
         $this->setMessage("613", "The Contact is duplicated. Contact ID:  " . $idcontact);
         return false;
     } else {
         if ($this->company != "") {
             $do_api_contact->company = $this->company;
             $do_api_company = new Company();
             $idcompany = $do_api_company->isDuplicateCompany($this->company, $this->iduser);
             if (!$idcompany) {
                 $do_api_company->addNew();
                 $do_api_company->iduser = $this->iduser;
                 $do_api_company->name = trim($this->company);
                 $do_api_company->add();
                 $this->idcompany = $do_api_company->getPrimaryKeyValue();
             } else {
                 $this->idcompany = $idcompany;
             }
             $do_api_contact->idcompany = $this->idcompany;
         }
         $do_api_contact->add();
         $this->idcontact = $do_api_contact->getPrimaryKeyValue();
         $do_api_contact->idcontact = $this->idcontact;
         //child data starts here
         // Phones
         if ($this->phone_work != "") {
             $do_api_contact->addPhone($this->phone_work, "Work");
         }
         if ($this->phone_home != "") {
             $do_api_contact->addPhone($this->phone_home, "Home");
         }
         if ($this->mobile_number != "") {
             $do_api_contact->addPhone($this->mobile_number, "Mobile");
         }
         if ($this->fax_number != "") {
             $do_api_contact->addPhone($this->fax_number, "Fax");
         }
         if ($this->phone_other != "") {
             $do_api_contact->addPhone($this->phone_other, "Other");
         }
         //emails
         if ($this->email_work != "") {
             $do_api_contact->addEmail($this->email_work, "Work");
         }
         if ($this->email_home != "") {
             $do_api_contact->addEmail($this->email_home, "Home");
         }
         if ($this->email_other != "") {
             $do_api_contact->addEmail($this->email_other, "Other");
         }
         //Website
         if ($this->company_website != "") {
             $do_api_contact->addWebsite($this->company_website, "Company");
         }
         if ($this->personal_website != "") {
             $do_api_contact->addWebsite($this->personal_website, "Personal");
         }
         if ($this->blog_url != "") {
             $do_api_contact->addWebsite($this->blog_url, "Blog");
         }
         if ($this->twitter_profile_url != "") {
             $do_api_contact->addWebsite($this->twitter_profile_url, "Twitter");
         }
         if ($this->linkedin_profile_url != "") {
             $do_api_contact->addWebsite($this->linkedin_profile_url, "LinkedIn");
         }
         if ($this->facebook_profile_url != "") {
             $do_api_contact->addWebsite($this->facebook_profile_url, "Facebook");
         }
         // API V.02 will have IM and Address
         //Add tags if any
         if (is_array($tags)) {
             $do_api_tags = new Tag();
             foreach ($tags as $tag) {
                 $do_api_tags->addNew();
                 $do_api_tags->addTagAssociation($this->idcontact, $tag, "contact", $this->iduser);
             }
         }
         // Ok here the last thing that needs to be done so that the contact should also on the table
         $do_Contact_View = new ContactView();
         $do_Contact_View->setUser($this->iduser);
         $do_api_contact->getId($this->idcontact);
         $do_Contact_View->addFromContact($do_api_contact);
         $do_Contact_View->updateFromContact($do_api_contact);
         if ($this->tags != '') {
             $do_Contact_View->addTag($this->tags, $this->idcontact);
         }
         $this->setValues(array("msg" => "Contact Added", "stat" => "ok", "code" => "600", "idcontact" => $this->idcontact));
         return true;
     }
 }
Beispiel #20
0
 protected function addContact()
 {
     $contact = new Contact();
     $contact->name[Configuration::get('PS_LANG_DEFAULT')] = "Price negotiation";
     $contact->description[Configuration::get('PS_LANG_DEFAULT')] = "Negotiate price with seller";
     $contact->email = Configuration::get('PS_SHOP_EMAIL');
     if ($contact->add()) {
         Configuration::updateValue('ASKFORPRICE_CONTACT', $contact->id);
     }
     return $contact->id;
 }
Beispiel #21
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);
 }
 /**
  * Transfer contacts of an enterprise
  *
  * @param $ID original ID of the enterprise
  * @param $newID new ID of the enterprise
  **/
 function transferSupplierContacts($ID, $newID)
 {
     global $DB;
     $need_clean_process = false;
     // if keep
     if ($this->options['keep_contact']) {
         $contact = new Contact();
         // Get contracts for the item
         $query = "SELECT *\n                   FROM `glpi_contacts_suppliers`\n                   WHERE `suppliers_id` = '{$ID}'\n                         AND `contacts_id` NOT IN " . $this->item_recurs['Contact'];
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result) > 0) {
                 // Foreach get item
                 while ($data = $DB->fetch_array($result)) {
                     $need_clean_process = false;
                     $item_ID = $data['contacts_id'];
                     $newcontactID = -1;
                     // is already transfer ?
                     if (isset($this->already_transfer['Contact'][$item_ID])) {
                         $newcontactID = $this->already_transfer['Contact'][$item_ID];
                         if ($newcontactID != $item_ID) {
                             $need_clean_process = true;
                         }
                     } else {
                         $canbetransfer = true;
                         // Transfer enterprise : is the contact used for another enterprise ?
                         if ($ID == $newID) {
                             $query_search = "SELECT count(*) AS CPT\n                                         FROM `glpi_contacts_suppliers`\n                                         WHERE `contacts_id` = '{$item_ID}'\n                                               AND `suppliers_id`\n                                                    NOT IN " . $this->item_search['Supplier'] . "\n                                               AND `suppliers_id`\n                                                    NOT IN " . $this->item_recurs['Supplier'];
                             $result_search = $DB->query($query_search);
                             if ($DB->result($result_search, 0, 'CPT') > 0) {
                                 $canbetransfer = false;
                             }
                         }
                         // Yes : transfer
                         if ($canbetransfer) {
                             $this->transferItem('Contact', $item_ID, $item_ID);
                             $newcontactID = $item_ID;
                         } else {
                             $need_clean_process = true;
                             $contact->getFromDB($item_ID);
                             // No : search contract
                             $query = "SELECT *\n                                  FROM `glpi_contacts`\n                                  WHERE `entities_id` = '" . $this->to . "'\n                                        AND `name` = '" . addslashes($contact->fields['name']) . "'\n                                        AND `firstname`\n                                                = '" . addslashes($contact->fields['firstname']) . "'";
                             if ($result_search = $DB->query($query)) {
                                 if ($DB->numrows($result_search) > 0) {
                                     $newcontactID = $DB->result($result_search, 0, 'id');
                                     $this->addToAlreadyTransfer('Contact', $item_ID, $newcontactID);
                                 }
                             }
                             // found : use it
                             // not found : copy contract
                             if ($newcontactID < 0) {
                                 // 1 - create new item
                                 unset($contact->fields['id']);
                                 $input = $contact->fields;
                                 $input['entities_id'] = $this->to;
                                 unset($contact->fields);
                                 $newcontactID = $contact->add($input);
                                 // 2 - transfer as copy
                                 $this->transferItem('Contact', $item_ID, $newcontactID);
                             }
                         }
                     }
                     // Update links
                     if ($ID == $newID) {
                         if ($item_ID != $newcontactID) {
                             $query = "UPDATE `glpi_contacts_suppliers`\n                                  SET `contacts_id` = '{$newcontactID}'\n                                  WHERE `id` = '" . $data['id'] . "'";
                             $DB->query($query);
                         }
                         // Same Item -> update links
                     } else {
                         // Copy Item -> copy links
                         if ($item_ID != $newcontactID) {
                             $query = "INSERT\n                                  INTO `glpi_contacts_suppliers`\n                                  (`contacts_id`, `suppliers_id`)\n                                  VALUES ('{$newcontactID}','{$newID}')";
                             $DB->query($query);
                         } else {
                             // transfer contact but copy enterprise : update link
                             $query = "UPDATE `glpi_contacts_suppliers`\n                                  SET `suppliers_id` = '{$newID}'\n                                  WHERE `id` = '" . $data['id'] . "'";
                             $DB->query($query);
                         }
                     }
                     // If clean and unused ->
                     if ($need_clean_process && $this->options['clean_contact']) {
                         $query = "SELECT COUNT(*) AS CPT\n                               FROM `glpi_contacts_suppliers`\n                               WHERE `contacts_id` = '{$item_ID}'";
                         if ($result_remaining = $DB->query($query)) {
                             if ($DB->result($result_remaining, 0, 'CPT') == 0) {
                                 if ($this->options['clean_contact'] == 1) {
                                     $contact->delete(array('id' => $item_ID));
                                 }
                                 if ($this->options['clean_contact'] == 2) {
                                     // purge
                                     $contact->delete(array('id' => $item_ID), 1);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         // else unlink
         $query = "DELETE\n                   FROM `glpi_contacts_suppliers`\n                   WHERE `suppliers_id` = '{$ID}'";
         $DB->query($query);
     }
 }
Beispiel #23
0
function ajax_add_contact()
{
    if (Auth::guest()) {
        exit;
    }
    $userId = Auth::user()->id;
    $id = isset($_POST['id']) ? $_POST['id'] : 0;
    json_message(Contact::add($userId, $id));
}