[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/soap/ -> thunderbirdplugin.php (source)

   1  <?php
   2  /*********************************************************************************
   3  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9  *
  10   ********************************************************************************/
  11  
  12  /**
  13   * URL Verfication - Required to overcome Apache mis-configuration and leading to shared setup mode.
  14   */
  15  require_once  'config.php';
  16  if (file_exists('config_override.php')) {
  17                      include_once 'config_override.php';
  18  }
  19  
  20  include_once  'vtlib/Vtiger/Module.php';
  21  include_once  'includes/main/WebUI.php';
  22  
  23  require_once ('libraries/nusoap/nusoap.php');
  24  
  25  require_once ('modules/Contacts/Contacts.php');
  26  
  27  $log = &LoggerManager::getLogger('thunderbirdplugin');
  28  
  29  $accessDenied = "You are not authorized for performing this action";
  30  $NAMESPACE = 'http://www.vtiger.com/products/crm';
  31  $server = new soap_server;
  32  
  33  $server->configureWSDL('vtigersoap');
  34  
  35  $server->register(
  36           'create_session',
  37          array('user_name'=>'xsd:string','password'=>'xsd:string','version'=>'xsd:string'),
  38           array('return'=>'xsd:string'),
  39           $NAMESPACE);
  40  
  41  $server->register(
  42           'end_session',
  43           array('user_name'=>'xsd:string'),
  44           array('return'=>'xsd:string'),
  45           $NAMESPACE);
  46  
  47  $server->register(
  48      'SearchContactsByEmail',
  49      array('username'=>'xsd:string','password'=>'xsd:string','emailaddress'=>'xsd:string'),
  50      array('return'=>'tns:contactdetails'),
  51      $NAMESPACE);
  52  
  53  $server->register(
  54          'GetContacts',
  55      array('username'=>'xsd:string','password'=>'xsd:string'),
  56      array('return'=>'tns:contactdetails'),
  57      $NAMESPACE);
  58  
  59  $server->register(
  60      'CheckContactPerm',array('user_name'=>'xsd:string','password'=>'xsd:string'),
  61      array('return'=>'xsd:string'),$NAMESPACE);
  62  
  63  $server->register(
  64      'CheckContactViewPerm',array('user_name'=>'xsd:string','password'=>'xsd:string'),
  65      array('return'=>'xsd:string'),$NAMESPACE);
  66  
  67  $server->register(
  68      'CheckContactEmailPerm',array('user_name'=>'xsd:string','password'=>'xsd:string'),
  69      array('return'=>'xsd:string'),$NAMESPACE);
  70  
  71  $server->register(
  72      'CheckLeadViewPerm',array('user_name'=>'xsd:string','password'=>'xsd:string'),
  73      array('return'=>'xsd:string'),$NAMESPACE);
  74  
  75  $server->register(
  76        'AddContact',
  77    array('user_name'=>'xsd:string',
  78            'first_name'=>'xsd:string',
  79            'last_name'=>'xsd:string',
  80            'email_address'=>'xsd:string',
  81            'account_name'=>'xsd:string',
  82            'salutation'=>'xsd:string',
  83            'title'=>'xsd:string',
  84            'phone_mobile'=>'xsd:string',
  85            'reports_to'=>'xsd:string',
  86            'primary_address_street'=>'xsd:string',
  87            'primary_address_city'=>'xsd:string',
  88            'primary_address_state'=>'xsd:string' ,
  89            'primary_address_postalcode'=>'xsd:string',
  90            'primary_address_country'=>'xsd:string',
  91            'alt_address_city'=>'xsd:string',
  92            'alt_address_street'=>'xsd:string',
  93            'alt_address_state'=>'xsd:string',
  94            'alt_address_postalcode'=>'xsd:string',
  95            'alt_address_country'=>'xsd:string',
  96            'office_phone'=>'xsd:string',
  97            'home_phone'=>'xsd:string',
  98            'fax'=>'xsd:string',
  99        'department'=>'xsd:string',
 100          'password'=>'xsd:string',
 101            'description'=>'xsd:string'),
 102      array('return'=>'xsd:string'),
 103      $NAMESPACE);
 104  
 105  $server->register(
 106    'AddLead',
 107      array('user_name'=>'xsd:string',
 108            'first_name'=>'xsd:string',
 109            'last_name'=>'xsd:string',
 110            'email_address'=>'xsd:string',
 111            'account_name'=>'xsd:string',
 112            'salutation'=>'xsd:string',
 113            'title'=>'xsd:string',
 114            'phone_mobile'=>'xsd:string',
 115            'reports_to'=>'xsd:string',
 116            'primary_address_street'=>'xsd:string',
 117            'primary_address_city'=>'xsd:string',
 118            'primary_address_state'=>'xsd:string' ,
 119            'primary_address_postalcode'=>'xsd:string',
 120            'primary_address_country'=>'xsd:string',
 121            'alt_address_city'=>'xsd:string',
 122            'alt_address_street'=>'xsd:string',
 123            'alt_address_state'=>'xsd:string',
 124            'alt_address_postalcode'=>'xsd:string',
 125            'alt_address_country'=>'xsd:string',
 126            'office_phone'=>'xsd:string',
 127            'home_phone'=>'xsd:string',
 128            'fax'=>'xsd:string',
 129        'department'=>'xsd:string',
 130            'password'=>'xsd:string',
 131        'description'=>'xsd:string'),
 132      array('return'=>'xsd:string'),
 133      $NAMESPACE);
 134  
 135  $server->register(
 136      'track_email',
 137      array('user_name'=>'xsd:string','password'=>'xsd:string', 'contact_ids'=>'xsd:string', 'date_sent'=>'xsd:string', 'email_subject'=>'xsd:string', 'email_body'=>'xsd:string'),
 138      array('return'=>'xsd:string'),
 139      $NAMESPACE);
 140  
 141  $server->wsdl->addComplexType(
 142      'contactdetail',
 143      'complexType',
 144      'struct',
 145      'all',
 146      '',
 147      array(
 148      'id' => array('name'=>'id','type'=>'xsd:string'),
 149          'firstname' => array('name'=>'firstname','type'=>'xsd:string'),
 150          'lastname' => array('name'=>'lastname','type'=>'xsd:string'),
 151          'emailaddress' => array('name'=>'emailaddress','type'=>'xsd:string'),
 152          'accountname' => array('name'=>'accountname','type'=>'xsd:string'),
 153          'middlename' => array('name'=>'middlename','type'=>'xsd:string'),
 154          'birthdate'=> array('name'=>'birthdate','type'=>'xsd:string'),
 155          'jobtitle'=> array('name'=>'jobtitle','type'=>'xsd:string'),
 156          'department'=> array('name'=>'department','type'=>'xsd:string'),
 157          'title' => array('name'=>'title','type'=>'xsd:string'),
 158          'officephone'=> array('name'=>'officephone','type'=>'xsd:string'),
 159          'homephone'=> array('name'=>'homephone','type'=>'xsd:string'),
 160          'otherphone'=> array('name'=>'otherphone','type'=>'xsd:string'),
 161          'fax'=> array('name'=>'fax','type'=>'xsd:string'),
 162          'mobile'=> array('name'=>'mobile','type'=>'xsd:string'),
 163          'asstname'=> array('name'=>'asstname','type'=>'xsd:string'),
 164          'asstphone'=> array('name'=>'asstphone','type'=>'xsd:string'),
 165          'reportsto'=> array('name'=>'reportsto','type'=>'xsd:string'),
 166          'mailingstreet'=> array('name'=>'mailingstreet','type'=>'xsd:string'),
 167          'mailingcity'=> array('name'=>'mailingcity','type'=>'xsd:string'),
 168          'mailingstate'=> array('name'=>'mailingstate','type'=>'xsd:string'),
 169          'mailingzip'=> array('name'=>'mailingzip','type'=>'xsd:string'),
 170          'mailingcountry'=> array('name'=>'mailingcountry','type'=>'xsd:string'),
 171          'otherstreet'=> array('name'=>'otherstreet','type'=>'xsd:string'),
 172          'othercity'=> array('name'=>'othercity','type'=>'xsd:string'),
 173          'otherstate'=> array('name'=>'otherstate','type'=>'xsd:string'),
 174          'otherzip'=> array('name'=>'otherzip','type'=>'xsd:string'),
 175          'othercountry'=> array('name'=>'othercountry','type'=>'xsd:string'),
 176          'description'=> array('name'=>'description','type'=>'xsd:string'),
 177          'category'=> array('name'=>'category','type'=>'xsd:string'),
 178      )
 179  );
 180  
 181  $server->wsdl->addComplexType(
 182      'contactdetails',
 183      'complexType',
 184      'array',
 185      '',
 186      'SOAP-ENC:Array',
 187      array(),
 188      array(
 189          array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:contactdetail[]')
 190      ),
 191      'tns:contactdetail'
 192  );
 193  
 194  
 195  function SearchContactsByEmail($username,$password,$emailaddress)
 196  {
 197    if(authentication($username,$password))
 198    {
 199       require_once ('modules/Contacts/Contacts.php');
 200  
 201       $seed_contact = new Contacts();
 202       $output_list = Array();
 203  
 204       if(filter_var($emailaddress, FILTER_VALIDATE_EMAIL) == false ) return null;
 205       
 206       $response = $seed_contact->get_searchbyemailid($username,$emailaddress);
 207       $contactList = $response['list'];
 208  
 209       // create a return array of names and email addresses.
 210       foreach($contactList as $contact)
 211       {
 212            $output_list[] = Array(
 213                 "id" => decode_html($contact[contactid]),
 214                 "firstname" => decode_html($contact[firstname]),
 215                 "lastname" => decode_html($contact[lastname]),
 216                 "emailaddress" => decode_html($contact[email]),
 217                 "accountname" => decode_html($contact[accountname]),
 218            );
 219       }
 220  
 221       //to remove an erroneous compiler warning
 222       $seed_contact = $seed_contact;
 223       return $output_list;
 224    }
 225  }
 226  
 227  function track_email($user_name,$password,$contact_ids, $date_sent, $email_subject, $email_body)
 228  {
 229      if(authentication($user_name,$password))
 230      {
 231          global $current_user;
 232          global $adb;
 233          global $log;
 234          require_once ('modules/Users/Users.php');
 235          require_once ('modules/Emails/Emails.php');
 236          $current_user = new Users();
 237          $user_id = $current_user->retrieve_user_id($user_name);
 238          $query = "select email1 from vtiger_users where id =?";
 239          $result = $adb->pquery($query, array($user_id));
 240          $user_emailid = $adb->query_result($result,0,"email1");
 241          $current_user = $current_user->retrieveCurrentUserInfoFromFile($user_id);
 242          $email = new Emails();
 243          //$log->debug($msgdtls['contactid']);
 244          $emailbody = str_replace("'", "''", $email_body);
 245          $emailsubject = str_replace("'", "''",$email_subject);
 246          $datesent = substr($date_sent,1,10);
 247          $mydate = date('Y-m-d',$datesent);
 248          $mydate = DateTimeField::convertToDBFormat($mydate);
 249          $email->column_fields[subject] = $emailsubject;
 250          $email->column_fields[assigned_user_id] = $user_id;
 251          $email->column_fields[date_start] = $mydate;
 252          $email->column_fields[description]  = $emailbody;
 253          $email->column_fields[activitytype] = 'Emails';
 254          $email->plugin_save = true;
 255          $email->save("Emails");
 256          $query = "select fieldid from vtiger_field where fieldname = 'email' and tabid = 4 and vtiger_field.presence in (0,2)";
 257          $result = $adb->pquery($query, array());
 258          $field_id = $adb->query_result($result,0,"fieldid");
 259          $email->set_emails_contact_invitee_relationship($email->id,$contact_ids);
 260          $email->set_emails_se_invitee_relationship($email->id,$contact_ids);
 261          $email->set_emails_user_invitee_relationship($email->id,$user_id);
 262          $sql = "select email from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid where vtiger_crmentity.deleted =0 and vtiger_contactdetails.contactid=?";
 263          $result = $adb->pquery($sql, array($contact_ids));
 264          $camodulerow = $adb->fetch_array($result);
 265          if(isset($camodulerow))
 266          {
 267              $emailid = $camodulerow["email"];
 268      
 269                  //added to save < as $lt; and > as &gt; in the database so as to retrive the emailID
 270                  $user_emailid = str_replace('<','&lt;',$user_emailid);
 271                  $user_emailid = str_replace('>','&gt;',$user_emailid);
 272              $query = 'insert into vtiger_emaildetails values (?,?,?,?,?,?,?,?)';
 273              $params = array($email->id, $emailid, $user_emailid, "", "", "", $user_id.'@-1|'.$contact_ids.'@'.$field_id.'|',"THUNDERBIRD");
 274              $adb->pquery($query, $params);
 275          }
 276          return $email->id;
 277      }
 278  }
 279  
 280  function GetContacts($username,$password)
 281  {
 282      if(authentication($username,$password))
 283      {
 284          global $adb;
 285          global $log;
 286          require_once ('modules/Contacts/Contacts.php');
 287      
 288          $seed_contact = new Contacts();
 289          $output_list = Array();
 290      
 291          $query = $seed_contact->get_contactsforol($username);
 292          $result = $adb->pquery($query, array());
 293      
 294          while($contact = $adb->fetch_array($result))
 295          {
 296              if($contact["birthdate"] == "0000-00-00")
 297              {
 298                  $contact["birthdate"] = "";
 299              }
 300              if($contact["salutation"] == "--None--")
 301              {
 302                  $contact["salutation"] = "";
 303              }
 304              $output_list[] = Array(
 305                  "id" => decode_html($contact["id"]),
 306                  "title" => decode_html($contact["salutation"]),
 307                  "firstname" => decode_html($contact["firstname"]),
 308                  "middlename" => decode_html(trim($middlename)),
 309                  "lastname" => decode_html(trim($contact["lastname"])),
 310                  "birthdate" => $contact["birthday"],
 311                  "emailaddress" => decode_html($contact["email"]),
 312                  "jobtitle" => decode_html($contact["title"]),
 313                  "department" => decode_html($contact["department"]),
 314                  "accountname" => decode_html($contact["accountname"]),
 315                  "officephone" => decode_html($contact["phone"]),
 316                  "homephone" => decode_html($contact["homephone"]),
 317                  "otherphone" => decode_html($contact["otherphone"]),
 318                  "fax" => decode_html($contact["fax"]),
 319                  "mobile" => decode_html($contact["mobile"]),
 320                  "asstname" => decode_html($contact["assistant"]),
 321                  "asstphone" => decode_html($contact["assistantphone"]),
 322                  "reportsto" => decode_html($contact["reports_to_name"]),
 323                  "mailingstreet" => decode_html($contact["mailingstreet"]),
 324                  "mailingcity" => decode_html($contact["mailingcity"]),
 325                  "mailingstate" => decode_html($contact["mailingstate"]),
 326                  "mailingzip" => decode_html($contact["mailingzip"]),
 327                  "mailingcountry" => decode_html($contact["mailingcountry"]),
 328                  "otherstreet" => decode_html($contact["otherstreet"]),
 329                  "othercity" => decode_html($contact["othercity"]),
 330                  "otherstate" => decode_html($contact["otherstate"]),
 331                  "otherzip" => decode_html($contact["otherzip"]),
 332                  "othercountry" => decode_html($contact["othercountry"]),
 333                  "description" => "",
 334                  "category" => "",
 335                );
 336          }
 337          //to remove an erroneous compiler warning
 338          $seed_contact = $seed_contact;
 339          return $output_list;
 340      }
 341  }
 342  
 343  function retrieve_account_id($account_name,$user_id)
 344  {
 345  
 346      if($account_name=="")
 347      {
 348          return null;
 349      }
 350  
 351      $db = PearDatabase::getInstance();
 352      
 353      $query = "select vtiger_account.accountname accountname,vtiger_account.accountid accountid from vtiger_account inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid where vtiger_crmentity.deleted=0 and vtiger_account.accountname=?";
 354      $result=  $db->pquery($query, array($account_name)) or die ("Not able to execute insert");
 355  
 356      $rows_count =  $db->getRowCount($result);
 357      if($rows_count==0)
 358      {
 359          require_once ('modules/Accounts/Accounts.php');
 360          $account = new Accounts();
 361          $account->column_fields[accountname] = $account_name;
 362          $account->column_fields[assigned_user_id]=$user_id;
 363          //$account->saveentity("Accounts");
 364          $account->save("Accounts");
 365          //mysql_close();
 366          return $account->id;
 367      }
 368      else if ($rows_count==1)
 369      {
 370          $row = $db->fetchByAssoc($result, 0);
 371          //mysql_close();
 372          return $row["accountid"];
 373      }
 374      else
 375      {
 376          $row = $db->fetchByAssoc($result, 0);
 377          //mysql_close();
 378          return $row["accountid"];
 379      }
 380  
 381  }
 382  
 383  function AddContact($user_name,$first_name, $last_name, $email_address ,$account_name , $salutation , $title, $phone_mobile, $reports_to,$primary_address_street,$primary_address_city,$primary_address_state,$primary_address_postalcode,$primary_address_country,$alt_address_city,$alt_address_street,$alt_address_state,$alt_address_postalcode,$alt_address_country,$office_phone="",$home_phone="",$fax="",$department="",$password,$description="")
 384  {
 385      if(authentication($user_name,$password))
 386      {
 387          global $adb;
 388          global $current_user;
 389          require_once ('modules/Users/Users.php');
 390          require_once ('modules/Contacts/Contacts.php');
 391      
 392          $seed_user = new Users();
 393          $user_id = $seed_user->retrieve_user_id($user_name);
 394          $current_user = $seed_user;
 395          $current_user->retrieve_entity_info($user_id,"Users");
 396          checkFileAccessForInclusion('user_privileges/user_privileges_'.$current_user->id.'.php');
 397          require('user_privileges/user_privileges_'.$current_user->id.'.php');
 398          checkFileAccessForInclusion('user_privileges/sharing_privileges_'.$current_user->id.'.php');
 399          require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
 400      
 401          if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
 402              $sql1 = "select fieldname,columnname from vtiger_field where tabid=4 and block <> 75 and block <> 6 and block <> 5 and vtiger_field.presence in (0,2)";
 403              $params1 = array();
 404            } else {
 405              $profileList = getCurrentUserProfileList();
 406              $sql1 = "select fieldname,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=4 and vtiger_field.block <> 75 and vtiger_field.block <> 6 and vtiger_field.block <> 5 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
 407              $params1 = array();
 408              if (count($profileList) > 0) {
 409                  $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
 410                  array_push($params1, $profileList);
 411              }
 412            }
 413            $result1 = $adb->pquery($sql1, $params1);
 414    
 415            for($i=0;$i < $adb->num_rows($result1);$i++)
 416            {
 417              $permitted_lists[] = $adb->query_result($result1,$i,'fieldname');
 418            }
 419      
 420          $contact = new Contacts();
 421          $contact->column_fields[firstname]=in_array('firstname',$permitted_lists) ? $first_name : "";
 422          $contact->column_fields[lastname]=in_array('lastname',$permitted_lists) ? $last_name : "";    
 423          $contact->column_fields[email]=in_array('email',$permitted_lists) ? $email_address : "";
 424          $contact->column_fields[title]=in_array('title',$permitted_lists) ? $title : "";
 425          $contact->column_fields[department]=in_array('department',$permitted_lists) ? $department : "";
 426          $contact->column_fields[account_id]=in_array('account_id',$permitted_lists) ? retrieve_account_id($account_name,$user_id) : "";
 427          $contact->column_fields[phone]=in_array('phone',$permitted_lists) ? $office_phone : "";
 428          $contact->column_fields[homephone]=in_array('homephone',$permitted_lists) ? $home_phone : "";
 429          $contact->column_fields[fax]=in_array('fax',$permitted_lists) ? $fax : "";
 430          $contact->column_fields[mobile]=in_array('mobile',$permitted_lists) ? $phone_mobile : "";
 431          $contact->column_fields[mailingstreet]=in_array('mailingstreet',$permitted_lists) ? $primary_address_street : "";
 432          $contact->column_fields[mailingcity]=in_array('mailingcity',$permitted_lists) ? $primary_address_city : "";
 433          $contact->column_fields[mailingstate]=in_array('mailingstate',$permitted_lists) ? $primary_address_state : "";
 434          $contact->column_fields[mailingzip]=in_array('mailingzip',$permitted_lists) ? $primary_address_postalcode : "";
 435          $contact->column_fields[mailingcountry]=in_array('mailingcountry',$permitted_lists) ? $primary_address_country : "";
 436          $contact->column_fields[otherstreet]=in_array('otherstreet',$permitted_lists) ? $alt_address_street : "";
 437          $contact->column_fields[othercity]=in_array('othercity',$permitted_lists) ? $alt_address_city : "";
 438          $contact->column_fields[otherstate]=in_array('otherstate',$permitted_lists) ? $alt_address_state : "";
 439          $contact->column_fields[otherzip]=in_array('otherzip',$permitted_lists) ? $alt_address_postalcode : "";
 440          $contact->column_fields[othercountry]=in_array('othercountry',$permitted_lists) ? $alt_address_country : "";
 441          $contact->column_fields[assigned_user_id]=in_array('assigned_user_id',$permitted_lists) ? $user_id : "";
 442          $contact->column_fields[description]= "";
 443          $contact->save("Contacts");
 444      
 445        $contact = $contact;
 446          return $contact->id;
 447      }
 448  }
 449  
 450  function AddLead($user_name, $first_name, $last_name, $email_address ,$account_name , $salutation , $title, $phone_mobile, $reports_to ,$primary_address_street , $website ,$primary_address_city,$primary_address_state,$primary_address_postalcode,$primary_address_country,$alt_address_city,$alt_address_street,$alt_address_state,$alt_address_postalcode,$alt_address_country,$office_phone="",$home_phone="",$fax="",$department="",$password,$description="")
 451  {
 452      if(authentication($user_name,$password))
 453      {
 454          global $adb;
 455          global $current_user;
 456          require_once ('modules/Users/Users.php');
 457          require_once ('modules/Leads/Leads.php');
 458      
 459          $seed_user = new Users();
 460          $user_id = $seed_user->retrieve_user_id($user_name);
 461          $current_user = $seed_user;
 462          $current_user->retrieve_entity_info($user_id,"Users");
 463          checkFileAccessForInclusion('user_privileges/user_privileges_'.$current_user->id.'.php');
 464          require('user_privileges/user_privileges_'.$current_user->id.'.php');
 465          checkFileAccessForInclusion('user_privileges/sharing_privileges_'.$current_user->id.'.php');
 466          require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
 467      
 468          if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
 469              $sql1 = "select fieldname,columnname from vtiger_field where tabid=7 and block <> 14 and vtiger_field.presence in (0,2)";
 470              $params1 = array();
 471            } else {
 472              $profileList = getCurrentUserProfileList();
 473              $sql1 = "select fieldname,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=7 and vtiger_field.block <> 14 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)";
 474                $params1 = array();
 475              if (count($profileList) > 0) {
 476                  $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")";
 477                  array_push($params1, $profileList);
 478              }
 479          }
 480            $result1 = $adb->pquery($sql1, $params1);
 481            for($i=0;$i < $adb->num_rows($result1);$i++)
 482            {
 483            $permitted_lists[] = $adb->query_result($result1,$i,'fieldname');
 484            }
 485      
 486          $Lead = new Leads();
 487          $Lead->column_fields[firstname]=in_array('firstname',$permitted_lists) ? $first_name : "";
 488          $Lead->column_fields[lastname]=in_array('lastname',$permitted_lists) ? $last_name : "";
 489          $Lead->column_fields[company]=in_array('company',$permitted_lists) ? $account_name : "";
 490          $Lead->column_fields[email]=in_array('email',$permitted_lists) ? $email_address : "";
 491          $Lead->column_fields[title]=in_array('title',$permitted_lists) ? $title : "";
 492          $Lead->column_fields[designation]=in_array('designation',$permitted_lists) ? $department : "";
 493          $Lead->column_fields[phone]=in_array('phone',$permitted_lists) ? $office_phone : "";
 494          $Lead->column_fields[homephone]=in_array('homephone',$permitted_lists) ? $home_phone : "";
 495          $Lead->column_fields[website]=in_array('website',$permitted_lists) ? $website : "";
 496          $Lead->column_fields[fax]=in_array('fax',$permitted_lists) ? $fax : "";
 497          $Lead->column_fields[mobile]=in_array('mobile',$permitted_lists) ? $phone_mobile : "";
 498          $Lead->column_fields[mailingstreet]=in_array('mailingstreet',$permitted_lists) ? $primary_address_street : "";
 499          $Lead->column_fields[mailingcity]=in_array('mailingcity',$permitted_lists) ? $primary_address_city : "";
 500          $Lead->column_fields[mailingstate]=in_array('mailingstate',$permitted_lists) ? $primary_address_state : "";
 501          $Lead->column_fields[mailingzip]=in_array('mailingzip',$permitted_lists) ? $primary_address_postalcode : "";
 502          $Lead->column_fields[workCountry]=in_array('mailingcountry',$permitted_lists) ? $workCountry : "";
 503          $Lead->column_fields[lane]=in_array('lane',$permitted_lists) ? $alt_address_street : "";
 504          $Lead->column_fields[city]=in_array('city',$permitted_lists) ? $alt_address_city : "";
 505          $Lead->column_fields[state]=in_array('state',$permitted_lists) ? $alt_address_state : "";
 506          $Lead->column_fields[code]=in_array('code',$permitted_lists) ? $alt_address_postalcode : "";
 507          $Lead->column_fields[country]=in_array('country',$permitted_lists) ? $alt_address_country : "";
 508          $Lead->column_fields[assigned_user_id]=in_array('assigned_user_id',$permitted_lists) ? $user_id : "";
 509          $Lead->column_fields[description]= "";
 510      //    $log->fatal($Lead->column_fields);
 511          $Lead->save("Leads");
 512      
 513            $Lead = $Lead;
 514          return $Lead->id;
 515      }
 516  }
 517  
 518  function create_session($user_name, $password,$version)
 519  {
 520    global $adb,$log;
 521    $return_access = 'FALSES';
 522    include ('vtigerversion.php');
 523   
 524      /* Make 5.0.4 plugins compatible with 5.1.0 */
 525      if(version_compare($version,'5.0.4', '>=') === 1) {
 526          return array("VERSION",'00');
 527      }
 528  
 529        require_once ('modules/Users/Users.php');
 530      $objuser = new Users();
 531      if($password != "" && $user_name != '')
 532      {
 533          $objuser->column_fields['user_name'] = $user_name;
 534          $encrypted_password = $objuser->encrypt_password($password);
 535          if($objuser->load_user($password) && $objuser->is_authenticated())
 536          {
 537              $query = "select id from vtiger_users where user_name=? and user_password=?";
 538              $result = $adb->pquery($query, array($user_name, $encrypted_password));
 539              if($adb->num_rows($result) > 0)
 540              {
 541                  $return_access = 'TRUES';
 542                  $log->debug("Logged in sucessfully from thunderbirdplugin");
 543              }else
 544              {
 545                  $return_access = 'FALSES';
 546                  $log->debug("Logged in failure from thunderbirdplugin");
 547              }
 548          }
 549          else
 550          {
 551              $return_access = 'LOGIN';
 552              $log->debug("Logged in failure from thunderbirdplugin");    
 553          }
 554      }else
 555      {
 556          $return_access = 'FALSES';
 557          $log->debug("Logged in failure from thunderbirdplugin");
 558      }
 559      return $return_access;
 560  }
 561  function authentication($user_name,$password)
 562  {
 563      global $adb,$log;
 564      require_once ('modules/Users/Users.php');
 565      $objuser = new Users();
 566      if($password != "" && $user_name != '')
 567      {
 568          $objuser->column_fields['user_name'] = $user_name;
 569          $encrypted_password = $objuser->encrypt_password($password);
 570          if($objuser->load_user($password) && $objuser->is_authenticated())
 571          {
 572              $query = "select id from vtiger_users where user_name=? and user_password=?";
 573              $log->DEBUG("Running Query is ".$query);
 574              $result = $adb->pquery($query, array($user_name, $encrypted_password));
 575              if($adb->num_rows($result) > 0)
 576              {
 577                  return true;
 578              }else
 579              {
 580                  return false;
 581              }
 582          }
 583          else
 584          {
 585              return false;
 586          }
 587      }else
 588      {
 589          return false;
 590      }
 591      return false;
 592  }
 593  function end_session($user_name)
 594  {
 595          return "Success";
 596  }
 597  
 598  function CheckContactPerm($user_name,$password)
 599  {
 600      if(authentication($user_name,$password))
 601      {
 602          global $current_user;
 603          require_once ('modules/Users/Users.php');
 604          $seed_user = new Users();
 605          $user_id = $seed_user->retrieve_user_id($user_name);
 606          $current_user = $seed_user;
 607          $current_user->retrieve_entity_info($user_id,"Users");
 608          if(isPermitted("Contacts","EditView") == "yes")
 609          {
 610              return "allowed";
 611          }else
 612          {
 613              return "denied";
 614          }
 615      }
 616  }
 617  
 618  function CheckContactEmailPerm($user_name,$password)
 619  {
 620      if(authentication($user_name,$password))
 621      {
 622          global $current_user,$log;
 623          require_once ('modules/Users/Users.php');
 624          $seed_user = new Users();
 625          $user_id = $seed_user->retrieve_user_id($user_name);
 626          $current_user = $seed_user;
 627          $current_user->retrieve_entity_info($user_id,"Users");
 628          if((isPermitted("Contacts","index") == "yes") && (isPermitted("Emails","index") == "yes"))
 629          {    
 630              return "allowed";
 631          }else
 632          {
 633              return "notallowed";
 634          }
 635      }
 636  }    
 637  function CheckContactViewPerm($user_name,$password)
 638  {
 639      if(authentication($user_name,$password))
 640      {
 641          global $current_user,$log;
 642          require_once ('modules/Users/Users.php');
 643          $seed_user = new Users();
 644          $user_id = $seed_user->retrieve_user_id($user_name);
 645          $current_user = $seed_user;
 646          $current_user->retrieve_entity_info($user_id,"Users");
 647          if(isPermitted("Contacts","index") == "yes")
 648          {    
 649              return "allowed";
 650          }else
 651          {
 652              return "contact";
 653          }
 654      }
 655  }    
 656  
 657  function CheckLeadViewPerm($user_name)
 658  {
 659    global $current_user,$log;
 660      require_once ('modules/Users/Users.php');
 661      $seed_user = new Users();
 662      $user_id = $seed_user->retrieve_user_id($user_name);
 663      $current_user = $seed_user;
 664      $current_user->retrieve_entity_info($user_id,"Users");
 665      if(isPermitted("Leads","EditView") == "yes")
 666      {
 667          return "allowed";
 668      }else
 669      {
 670          return "denied";
 671      }
 672  }
 673  /* Begin the HTTP listener service and exit. */ 
 674  if (!isset($HTTP_RAW_POST_DATA)){
 675      $HTTP_RAW_POST_DATA = file_get_contents('php://input');
 676  }
 677  $server->service($HTTP_RAW_POST_DATA);
 678  exit();
 679  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1