| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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 require_once ("config.php"); 13 require_once ('include/logging.php'); 14 require_once ('include/nusoap/nusoap.php'); 15 require_once ('modules/HelpDesk/HelpDesk.php'); 16 require_once ('modules/Emails/mail.php'); 17 18 $log = &LoggerManager::getLogger('customerportal'); 19 20 //$serializer = new XML_Serializer(); 21 $NAMESPACE = 'http://www.vtigercrm.com/vtigercrm'; 22 $server = new soap_server; 23 24 $server->configureWSDL('vtigersoap'); 25 26 27 28 //Field array for vtiger_troubletickets 29 $server->wsdl->addComplexType( 30 'tickets_list_array', 31 'complexType', 32 'array', 33 '', 34 array( 35 'ticketid' => array('name'=>'ticketid','type'=>'xsd:string'), 36 'title' => array('name'=>'title','type'=>'xsd:string'), 37 'groupname' => array('name'=>'groupname','type'=>'xsd:string'), 38 'firstname' => array('name'=>'firstname','type'=>'xsd:string'), 39 'lastname' => array('name'=>'lastname','type'=>'xsd:string'), 40 'parent_id' => array('name'=>'parent_id','type'=>'xsd:string'), 41 'productid' => array('name'=>'productid','type'=>'xsd:string'), 42 'productname' => array('name'=>'productname','type'=>'xsd:string'), 43 'priority' => array('name'=>'priority','type'=>'xsd:string'), 44 'severity' => array('name'=>'severity','type'=>'xsd:string'), 45 'status' => array('name'=>'status','type'=>'xsd:string'), 46 'category' => array('name'=>'category','type'=>'xsd:string'), 47 'description' => array('name'=>'description','type'=>'xsd:string'), 48 'solution' => array('name'=>'solution','type'=>'xsd:string'), 49 'createdtime' => array('name'=>'createdtime','type'=>'xsd:string'), 50 'modifiedtime' => array('name'=>'modifiedtime','type'=>'xsd:string'), 51 ) 52 ); 53 54 $server->wsdl->addComplexType( 55 'ticket_comments_array', 56 'complexType', 57 'array', 58 '', 59 array( 60 'comments' => array('name'=>'comments','type'=>'tns:xsd:string'), 61 ) 62 ); 63 64 $server->wsdl->addComplexType( 65 'combo_values_array', 66 'complexType', 67 'array', 68 '', 69 array( 70 'productid' => array('name'=>'productid','type'=>'tns:xsd:string'), 71 'productname' => array('name'=>'productname','type'=>'tns:xsd:string'), 72 'ticketpriorities' => array('name'=>'ticketpriorities','type'=>'tns:xsd:string'), 73 'ticketseverities' => array('name'=>'ticketseverities','type'=>'tns:xsd:string'), 74 'ticketcategories' => array('name'=>'ticketcategories','type'=>'tns:xsd:string'), 75 'moduleslist' => array('name'=>'moduleslist','type'=>'tns:xsd:string'), 76 ) 77 ); 78 79 $server->wsdl->addComplexType( 80 'KBase_array', 81 'complexType', 82 'array', 83 '', 84 'SOAP-ENC:Array', 85 array(), 86 array( 87 array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:kbase_detail[]') 88 ), 89 'tns:kbase_detail' 90 ); 91 92 $server->wsdl->addComplexType( 93 'kbase_detail', 94 'complexType', 95 'array', 96 '', 97 array( 98 'faqcategory' => array('name'=>'faqcategory','type'=>'tns:xsd:string'), 99 'faq' => array( 100 'id' => array('name'=>'id','type'=>'tns:xsd:string'), 101 'question' => array('name'=>'question','type'=>'tns:xsd:string'), 102 'answer' => array('name'=>'answer','type'=>'tns:xsd:string'), 103 'category' => array('name'=>'category','type'=>'tns:xsd:string'), 104 'faqcreatedtime' => array('name'=>'createdtime','type'=>'tns:xsd:string'), 105 'faqmodifiedtime' => array('name'=>'createdtime','type'=>'tns:xsd:string'), 106 'faqcomments' => array('name'=>'faqcomments','type'=>'tns:xsd:string'), 107 ) 108 ) 109 ); 110 111 $server->wsdl->addComplexType( 112 'ticket_update_comment_array', 113 'complexType', 114 'array', 115 '', 116 array( 117 'ticketid' => array('name'=>'ticketid','type'=>'tns:xsd:string'), 118 'parent_id' => array('name'=>'parent_id','type'=>'tns:xsd:string'), 119 'createdtime' => array('name'=>'createdtime','type'=>'tns:xsd:string'), 120 'comments' => array('name'=>'comments','type'=>'tns:xsd:string'), 121 ) 122 ); 123 124 //Added for User Details 125 $server->wsdl->addComplexType( 126 'user_array', 127 'complexType', 128 'array', 129 '', 130 array( 131 'id' => array('name'=>'id','type'=>'xsd:string'), 132 'user_name' => array('name'=>'user_name','type'=>'xsd:string'), 133 'user_password' => array('name'=>'user_password','type'=>'xsd:string'), 134 'last_login' => array('name'=>'last_login_time','type'=>'xsd:string'), 135 'support_start_date' => array('name'=>'support_start_date','type'=>'xsd:string'), 136 'support_end_date' => array('name'=>'support_end_date','type'=>'xsd:string'), 137 ) 138 ); 139 140 //Added to get the picklist values as array 141 $server->wsdl->addComplexType( 142 'get_picklists_array', 143 'complexType', 144 'array', 145 '', 146 array( 147 'ticket_picklist' => array('name'=>'ticket_picklist','type'=>'tns:xsd:string'), 148 ) 149 ); 150 151 //Added for ticket vtiger_attachments 152 $server->wsdl->addComplexType( 153 'get_ticket_attachments_array', 154 'complexType', 155 'array', 156 '', 157 array( 158 'files' => array( 159 'fileid'=>'xsd:string','type'=>'tns:xsd:string', 160 'filename'=>'xsd:string','type'=>'tns:xsd:string', 161 'filesize'=>'xsd:string','type'=>'tns:xsd:string', 162 'filetype'=>'xsd:string','type'=>'tns:xsd:string', 163 'filecontents'=>'xsd:string','type'=>'tns:xsd:string' 164 ), 165 ) 166 ); 167 168 $server->wsdl->addComplexType( 169 'add_ticket_attachment_array', 170 'complexType', 171 'array', 172 '', 173 array( 174 'ticketid' => array('name'=>'ticketid','type'=>'xsd:string'), 175 'filename' => array('name'=>'filename','type'=>'xsd:string'), 176 'filetype' => array('name'=>'filetype','type'=>'xsd:string'), 177 'filesize' => array('name'=>'filesize','type'=>'xsd:string'), 178 'filecontents' => array('name'=>'filecontents','type'=>'xsd:string'), 179 ) 180 ); 181 182 183 184 185 186 $server->register( 187 'authenticate_user', 188 array('user_name'=>'xsd:string','password'=>'xsd:string'), 189 array('return'=>'tns:user_array'), 190 $NAMESPACE); 191 192 $server->register( 193 'change_password', 194 array('id'=>'xsd:string','user_name'=>'xsd:string','password'=>'xsd:string'), 195 array('return'=>'tns:user_array'), 196 $NAMESPACE); 197 198 $server->register( 199 'create_ticket', 200 array('title'=>'xsd:string','description'=>'xsd:string','priority'=>'xsd:string','severity'=>'xsd:string','category'=>'xsd:string','user_name'=>'xsd:string','parent_id'=>'xsd:string','product_id'=>'xsd:string','module'=>'xsd:string'), 201 array('return'=>'tns:tickets_list_array'), 202 $NAMESPACE); 203 204 $server->register( 205 'get_tickets_list', 206 array('user_name'=>'xsd:string','id'=>'xsd:string','where'=>'xsd:string','match'=>'xsd:string'), 207 array('return'=>'tns:tickets_list_array'), 208 $NAMESPACE); 209 210 $server->register( 211 'get_ticket_comments', 212 array('id'=>'xsd:string'), 213 array('return'=>'tns:ticket_comments_array'), 214 $NAMESPACE); 215 216 $server->register( 217 'get_combo_values', 218 array('id'=>'xsd:string'), 219 array('return'=>'tns:combo_values_array'), 220 $NAMESPACE); 221 222 $server->register( 223 'get_KBase_details', 224 array('id'=>'xsd:string'), 225 array('return'=>'tns:KBase_array'), 226 $NAMESPACE); 227 228 $server->register( 229 'save_faq_comment', 230 array('faqid'=>'xsd:string','comments'=>'xsd:string'), 231 array('return'=>'tns:KBase_array'), 232 $NAMESPACE); 233 234 //ContactSerialise fix by CraigF 235 $server->register( 236 'update_ticket_comment', 237 array('ticketid'=>'xsd:string', 238 'ownerid'=>'xsd:string', 239 'comments'=>'xsd:string'), 240 array('return'=>'tns:ticket_update_comment_array'), 241 $NAMESPACE); 242 //End 243 $server->register( 244 'close_current_ticket', 245 array('ticketid'=>'xsd:string'), 246 array('return'=>'xsd:string'), 247 $NAMESPACE); 248 249 $server->register( 250 'update_login_details', 251 array('id'=>'xsd:string','flag'=>'xsd:string'), 252 array('return'=>'tns:user_array'), 253 $NAMESPACE); 254 255 $server->register( 256 'send_mail_for_password', 257 array('email'=>'xsd:string'), 258 array('return'=>'xsd:string'), 259 $NAMESPACE); 260 261 $server->register( 262 'get_ticket_creator', 263 array('id'=>'xsd:string'), 264 array('return'=>'xsd:string'), 265 $NAMESPACE); 266 267 $server->register( 268 'get_picklists', 269 array('id'=>'xsd:string'), 270 array('return'=>'tns:get_picklists_array'), 271 $NAMESPACE); 272 273 $server->register( 274 'get_ticket_attachments', 275 array('id'=>'xsd:string','ticketid'=>'xsd:string'), 276 array('return'=>'tns:get_ticket_attachments_array'), 277 $NAMESPACE); 278 279 $server->register( 280 'add_ticket_attachment', 281 array('ticketid'=>'xsd:string','filename'=>'xsd:string','filetype'=>'xsd:string','filesize'=>'xsd:string','filecontents'=>'xsd:string'), 282 array('return'=>'tns:add_ticket_attachment_array'), 283 $NAMESPACE); 284 285 286 287 /** function used to get the list of ticket comments 288 * @param int $ticketid - ticket id 289 * return array $response - ticket comments and details as a array with elements comments, owner and createdtime which will be returned from the function get_ticket_comments_list 290 */ 291 function get_ticket_comments($ticketid) 292 { 293 $seed_ticket = new HelpDesk(); 294 $output_list = Array(); 295 296 $response = $seed_ticket->get_ticket_comments_list($ticketid); 297 298 return $response; 299 } 300 301 /** function used to get the combo values ie., picklist values of the HelpDesk module and also the list of products 302 * @param string $id - empty string (we wont use this value, just an input element) 303 * return array $output - array which contains the product id, product name, ticketpriorities, ticketseverities, ticketcategories and module owners list 304 */ 305 function get_combo_values($id) 306 { 307 global $adb; 308 $output = Array(); 309 $sql = "select * from vtiger_products inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_products.productid where vtiger_crmentity.deleted=0"; 310 $result = $adb->query($sql); 311 $noofrows = $adb->num_rows($result); 312 for($i=0;$i<$noofrows;$i++) 313 { 314 $output['productid']['productid'][$i] = $adb->query_result($result,$i,"productid"); 315 $output['productname']['productname'][$i] = $adb->query_result($result,$i,"productname"); 316 } 317 318 $result1 = $adb->query("select * from vtiger_ticketpriorities"); 319 for($i=0;$i<$adb->num_rows($result1);$i++) 320 { 321 $output['ticketpriorities']['ticketpriorities'][$i] = $adb->query_result($result1,$i,"ticketpriorities"); 322 } 323 324 $result2 = $adb->query("select * from vtiger_ticketseverities"); 325 for($i=0;$i<$adb->num_rows($result2);$i++) 326 { 327 $output['ticketseverities']['ticketseverities'][$i] = $adb->query_result($result2,$i,"ticketseverities"); 328 } 329 330 $result3 = $adb->query("select * from vtiger_ticketcategories"); 331 for($i=0;$i<$adb->num_rows($result3);$i++) 332 { 333 $output['ticketcategories']['ticketcategories'][$i] = $adb->query_result($result3,$i,"ticketcategories"); 334 } 335 336 //Added to get the modules list -- september 10 2005 337 $sql2 = "select vtiger_moduleowners.*,vtiger_tab.name from vtiger_moduleowners inner join vtiger_tab on vtiger_moduleowners.tabid = vtiger_tab.tabid order by vtiger_tab.tabsequence"; 338 $result4 = $adb->query($sql2); 339 for($i=0;$i<$adb->num_rows($result4);$i++) 340 { 341 $output['moduleslist']['moduleslist'][$i] = $adb->query_result($result4,$i,"name"); 342 } 343 344 return $output; 345 } 346 347 /** function to get the Knowledge base details 348 * @param string $id - empty string (we wont use this value, just an input element) 349 * return array $result - array which contains the faqcategory, all product ids , product names and all faq details 350 */ 351 function get_KBase_details($id='') 352 { 353 global $adb; 354 355 $category_query = "select * from vtiger_faqcategories"; 356 $category_result = $adb->query($category_query); 357 $category_noofrows = $adb->num_rows($category_result); 358 for($j=0;$j<$category_noofrows;$j++) 359 { 360 $faqcategory = $adb->query_result($category_result,$j,'faqcategories'); 361 $result['faqcategory'][$j] = $faqcategory; 362 } 363 364 $product_query = "select * from vtiger_products inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_products.productid where vtiger_crmentity.deleted=0"; 365 $product_result = $adb->query($product_query); 366 $product_noofrows = $adb->num_rows($product_result); 367 for($i=0;$i<$product_noofrows;$i++) 368 { 369 $productid = $adb->query_result($product_result,$i,'productid'); 370 $productname = $adb->query_result($product_result,$i,'productname'); 371 $result['product'][$i]['productid'] = $productid; 372 $result['product'][$i]['productname'] = $productname; 373 } 374 375 $faq_query = "select vtiger_faq.*, vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime from vtiger_faq inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_faq.id where vtiger_crmentity.deleted=0 and vtiger_faq.status='Published' order by vtiger_crmentity.modifiedtime DESC"; 376 $faq_result = $adb->query($faq_query); 377 $faq_noofrows = $adb->num_rows($faq_result); 378 for($k=0;$k<$faq_noofrows;$k++) 379 { 380 $faqid = $adb->query_result($faq_result,$k,'id'); 381 $result['faq'][$k]['id'] = $faqid; 382 $result['faq'][$k]['product_id'] = $adb->query_result($faq_result,$k,'product_id'); 383 $result['faq'][$k]['question'] = nl2br($adb->query_result($faq_result,$k,'question')); 384 $result['faq'][$k]['answer'] = nl2br($adb->query_result($faq_result,$k,'answer')); 385 $result['faq'][$k]['category'] = $adb->query_result($faq_result,$k,'category'); 386 $result['faq'][$k]['faqcreatedtime'] = $adb->query_result($faq_result,$k,'createdtime'); 387 $result['faq'][$k]['faqmodifiedtime'] = $adb->query_result($faq_result,$k,'modifiedtime'); 388 389 $faq_comment_query = "select * from vtiger_faqcomments where faqid=".$faqid." order by createdtime DESC"; 390 $faq_comment_result = $adb->query($faq_comment_query); 391 $faq_comment_noofrows = $adb->num_rows($faq_comment_result); 392 for($l=0;$l<$faq_comment_noofrows;$l++) 393 { 394 $faqcomments = nl2br($adb->query_result($faq_comment_result,$l,'comments')); 395 $faqcreatedtime = $adb->query_result($faq_comment_result,$l,'createdtime'); 396 if($faqcomments != '') 397 { 398 $result['faq'][$k]['comments'][$l] = $faqcomments; 399 $result['faq'][$k]['createdtime'][$l] = $faqcreatedtime; 400 } 401 } 402 } 403 $adb->println($result); 404 return $result; 405 } 406 407 /** function to save the faq comment 408 * @param int $faqid - faq id 409 * @param string $comment - comment to be added with the FAQ 410 * return array $result - This function will call get_KBase_details and return that array 411 */ 412 function save_faq_comment($faqid,$comment) 413 { 414 global $adb; 415 $createdtime = $adb->formatDate(date('YmdHis')); 416 if(trim($comment) != '') 417 { 418 $faq_query = "insert into vtiger_faqcomments values('',".$faqid.",'".$comment."',".$createdtime.")"; 419 $adb->query($faq_query); 420 } 421 $result = get_KBase_details(''); 422 return $result; 423 } 424 425 /** function used to get the tickets list 426 * @param string $user_name - customer name who has loggedin in the customer portal 427 * @param int $id - customer id ie., contact id who has loggedin in the customer portal 428 * @param string $where - where condition to get the tickets based on this condition if the customer enter the search criteria where as this is optional 429 * @param string $match - all or any, which will be entered when the customer entered multiple search conditions and whether we want to search all or any of the give conditions 430 * return array $output_list - This function will call get_user_tickets_list function and return the array with the ticket details 431 */ 432 function get_tickets_list($user_name,$id,$where='',$match='') 433 { 434 435 $seed_ticket = new HelpDesk(); 436 $output_list = Array(); 437 438 $response = $seed_ticket->get_user_tickets_list($user_name,$id,$where,$match); 439 $ticketsList = $response['list']; 440 441 // create a return array of ticket details. 442 foreach($ticketsList as $ticket) 443 { 444 $output_list[] = Array( 445 "ticketid" => $ticket[ticketid], 446 "title" => $ticket[title], 447 "firstname" => $ticket[firstname], 448 "lastname" => $ticket[lastname], 449 "parent_id"=> $ticket[parent_id], 450 "productid"=> $ticket[productid], 451 "productname"=> $ticket[productname], 452 "priority" => $ticket[priority], 453 "severity"=>$ticket[severity], 454 "status"=>$ticket[status], 455 "category"=>$ticket[category], 456 "description"=>$ticket[description], 457 "solution"=>$ticket[solution], 458 "createdtime"=>$ticket[createdtime], 459 "modifiedtime"=>$ticket[modifiedtime], 460 ); 461 } 462 463 //to remove an erroneous compiler warning 464 $seed_ticket = $seed_ticket; 465 466 return $output_list; 467 } 468 469 /** function used to create ticket which has been created from customer portal 470 * @param string $title - title of the ticket 471 * @param string $description - description of the ticket 472 * @param string $priority - priority of the ticket 473 * @param string $severity - severity of the ticket 474 * @param string $category - category of the ticket 475 * @param string $user_name - customer name 476 * @param string $parent_id - parent id ie., customer id as this customer is the parent for this ticket 477 * @param string $product_id - product id for the ticket 478 * @param string $module - module name where as based on this module we will get the module owner and assign this ticket to that corresponding user 479 * return array - currently created ticket array, if this is not created then all tickets list will be returned 480 */ 481 function create_ticket($title,$description,$priority,$severity,$category,$user_name,$parent_id,$product_id,$module) 482 { 483 global $adb; 484 485 $seed_ticket = new HelpDesk(); 486 $output_list = Array(); 487 488 $ticket = new HelpDesk(); 489 490 $ticket->column_fields[ticket_title] = $title; 491 $ticket->column_fields[description]=$description; 492 $ticket->column_fields[ticketpriorities]=$priority; 493 $ticket->column_fields[ticketseverities]=$severity; 494 $ticket->column_fields[ticketcategories]=$category; 495 $ticket->column_fields[ticketstatus]='Open'; 496 497 $ticket->column_fields[parent_id]=$parent_id; 498 $ticket->column_fields[product_id]=$product_id; 499 500 //Added to get the user based on module from vtiger_moduleowners -- 10-11-2005 501 $user_id = 1;//Default admin user id 502 if($module != '') 503 { 504 $res = $adb->query("select vtiger_moduleowners.*, vtiger_tab.name from vtiger_moduleowners inner join vtiger_tab on vtiger_moduleowners.tabid = vtiger_tab.tabid where name='".$module."'"); 505 if($adb->num_rows($res) > 0) 506 { 507 $user_id = $adb->query_result($res,0,"user_id"); 508 } 509 } 510 $ticket->column_fields[assigned_user_id]=$user_id; 511 512 $adb->println($ticket->column_fields); 513 $ticket->save("HelpDesk"); 514 515 $subject = '[From Portal][ Ticket ID : '.$ticket->id.' ] '.$title; 516 $contents = ' Ticket ID : '.$ticket->id.'<br> Ticket Title : '.$title.'<br><br>'.$description; 517 518 //get the contact email id who creates the ticket from portal and use this email as from email id in email 519 $result = $adb->query("select email from vtiger_contactdetails where contactid=".$parent_id); 520 $contact_email = $adb->query_result($result,0,'email'); 521 $from_email = $contact_email; 522 523 //send mail to assigned to user 524 $to_email = getUserEmailId('id',$user_id); 525 $adb->println("Send mail to the user who is the owner of the module about the portal ticket"); 526 $mail_status = send_mail('HelpDesk',$to_email,'',$from_email,$subject,$contents); 527 528 //send mail to the customer(contact who creates the ticket from portal) 529 $adb->println("Send mail to the customer(contact) who creates the portal ticket"); 530 $mail_status = send_mail('Contacts',$contact_email,'',$from_email,$subject,$contents); 531 532 $tickets_list = get_tickets_list($user_name,$parent_id); 533 foreach($tickets_list as $ticket_array) 534 { 535 if($ticket->id == $ticket_array['ticketid']) 536 { 537 $record_save = 1; 538 $record_array[0]['new_ticket'] = $ticket_array; 539 } 540 } 541 if($record_save == 1) 542 { 543 $adb->println("Ticket from Portal is saved with id => ".$ticket->id); 544 return $record_array; 545 } 546 else 547 { 548 $adb->println("There may be error in saving the ticket."); 549 return $tickets_list; 550 } 551 //return $tickets_list; 552 //return $ticket->id; 553 } 554 555 /** function used to update the ticket comment which is added from the customer portal 556 * @param int $ticketid - ticket id 557 * @param int $ownerid - customer ie., contact id who has added this ticket comment 558 * @param string $comments - comment which is added from the customer portal 559 * return void 560 */ 561 function update_ticket_comment($ticketid,$ownerid,$comments) 562 { 563 global $adb; 564 $servercreatedtime = $adb->formatDate(date('YmdHis')); 565 if(trim($comments) != '') 566 { 567 $sql = "insert into vtiger_ticketcomments values('',".$ticketid.",'".$comments."','".$ownerid."','customer',".$servercreatedtime.")"; 568 $adb->query($sql); 569 570 $updatequery = "update vtiger_crmentity set modifiedtime=".$servercreatedtime." where crmid=".$ticketid; 571 $adb->query($updatequery); 572 } 573 } 574 575 /** function used to close the ticket 576 * @param int $ticketid - ticket id 577 * return string - success or failure message will be returned based on the ticket close update query 578 */ 579 function close_current_ticket($ticketid) 580 { 581 global $adb; 582 $sql = "update vtiger_troubletickets set status='Closed' where ticketid=".$ticketid; 583 $result = $adb->query($sql); 584 if($result) 585 return "<br><b>Ticket status is updated as 'Closed'.</b>"; 586 else 587 return "<br><b>Ticket could not be closed.</br>"; 588 } 589 590 /** function used to authenticate whether the customer has access or not 591 * @param string $username - customer name for the customer portal 592 * @param string $password - password for the customer portal 593 * return array $list - returns array with all the customer details 594 */ 595 function authenticate_user($username,$password) 596 { 597 global $adb; 598 $current_date = date("Y-m-d"); 599 $sql = "select id, user_name, user_password,last_login_time, support_start_date, support_end_date from vtiger_portalinfo inner join vtiger_customerdetails on vtiger_portalinfo.id=vtiger_customerdetails.customerid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_portalinfo.id where vtiger_crmentity.deleted=0 and user_name='".$username."' and user_password = '".$password."' and isactive=1 and vtiger_customerdetails.support_end_date >= '".$current_date."'"; 600 $result = $adb->query($sql); 601 $list['id'] = $adb->query_result($result,0,'id'); 602 $list['user_name'] = $adb->query_result($result,0,'user_name'); 603 $list['user_password'] = $adb->query_result($result,0,'user_password'); 604 $list['last_login_time'] = $adb->query_result($result,0,'last_login_time'); 605 $list['support_start_date'] = $adb->query_result($result,0,'support_start_date'); 606 $list['support_end_date'] = $adb->query_result($result,0,'support_end_date'); 607 608 return $list; 609 } 610 611 /** function used to change the password for the customer portal 612 * @param int $id - customer id ie., contact id 613 * @param string $username - customer name 614 * @param string $password - new password to change 615 * return array $list - returns array with all the customer details 616 */ 617 function change_password($id,$username,$password) 618 { 619 global $adb; 620 $sql = "update vtiger_portalinfo set user_password='".$password."' where id=".$id." and user_name='".$username."'"; 621 $result = $adb->query($sql); 622 623 $list = authenticate_user($username,$password); 624 625 return $list; 626 } 627 628 /** function used to update the login details for the customer 629 * @param int $id - customer id 630 * @param $flag - login/logout, based on the login login or logout time will be updated for the customer 631 * return $list - empty value 632 */ 633 function update_login_details($id,$flag) 634 { 635 global $adb; 636 $current_time = $adb->formatDate(date('YmdHis')); 637 638 if($flag == 'login') 639 { 640 $sql = "update vtiger_portalinfo set login_time=".$current_time." where id=".$id; 641 $result = $adb->query($sql); 642 } 643 elseif($flag == 'logout') 644 { 645 $sql = "select * from vtiger_portalinfo where id=".$id; 646 $result = $adb->query($sql); 647 if($adb->num_rows($result) != 0) 648 $last_login = $adb->query_result($result,0,'login_time'); 649 650 $sql = "update vtiger_portalinfo set logout_time=".$current_time.", last_login_time='".$last_login."' where id=".$id; 651 $result = $adb->query($sql); 652 } 653 654 return $list; 655 } 656 657 /** function used to send mail to the customer when he forgot the password and want to retrieve the password 658 * @param string $mailid - email address of the customer 659 * return message about the mail sending whether entered mail id is correct or not or is there any problem in mail sending 660 */ 661 function send_mail_for_password($mailid) 662 { 663 global $adb; 664 665 $sql = "select * from vtiger_portalinfo where user_name='".$mailid."'"; 666 $user_name = $adb->query_result($adb->query($sql),0,'user_name'); 667 $password = $adb->query_result($adb->query($sql),0,'user_password'); 668 $isactive = $adb->query_result($adb->query($sql),0,'isactive'); 669 670 $fromquery = "select vtiger_users.user_name, vtiger_users.email1 from vtiger_users inner join vtiger_crmentity on vtiger_users.id = vtiger_crmentity.smownerid inner join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_crmentity.crmid where vtiger_contactdetails.email ='".$mailid."'"; 671 $initialfrom = $adb->query_result($adb->query($fromquery),0,'user_name'); 672 $from = $adb->query_result($adb->query($fromquery),0,'email1'); 673 674 $contents = "<br>Following are your Customer Portal login details :"; 675 $contents .= "<br><br>User Name : ".$user_name; 676 $contents .= "<br>Password : ".$password; 677 678 $mail = new PHPMailer(); 679 680 $mail->Subject = "Regarding your Customer Portal login details"; 681 $mail->Body = $contents; 682 $mail->IsSMTP(); 683 684 $mailserverresult = $adb->query("select * from vtiger_systems where server_type='email'"); 685 $mail_server = $adb->query_result($mailserverresult,0,'server'); 686 $mail_server_username = $adb->query_result($mailserverresult,0,'server_username'); 687 $mail_server_password = $adb->query_result($mailserverresult,0,'server_password'); 688 $smtp_auth = $adb->query_result($mailserverresult,0,'smtp_auth'); 689 690 $mail->Host = $mail_server; 691 $mail->SMTPAuth = $smtp_auth; 692 $mail->Username = $mail_server_username; 693 $mail->Password = $mail_server_password; 694 $mail->From = $from; 695 $mail->FromName = $initialfrom; 696 697 $mail->AddAddress($user_name); 698 $mail->AddReplyTo($current_user->name); 699 $mail->WordWrap = 50; 700 701 $mail->IsHTML(true); 702 703 $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; 704 if($mailid == '') 705 { 706 return "false@@@<b>Please give your email id</b>"; 707 } 708 elseif($user_name == '' && $password == '') 709 { 710 return "false@@@<b>Please check your email id for Customer Portal</b>"; 711 } 712 elseif($isactive == 0) 713 { 714 return "false@@@<b>Your login is revoked. Please contact your admin.</b>"; 715 } 716 elseif(!$mail->Send()) 717 { 718 return "false@@@<b>Mail could not be sent</b>"; 719 } 720 else 721 return "true@@@<b>Mail has been sent to your mail id with the customer portal login details</b>"; 722 723 } 724 725 /** function used to get the ticket creater 726 * @param int $ticketid - ticket id 727 * return int $creator - ticket created user id will be returned ie., smcreatorid from crmentity table 728 */ 729 function get_ticket_creator($ticketid) 730 { 731 global $adb; 732 733 $res = $adb->query("select smcreatorid from vtiger_crmentity where crmid=".$ticketid); 734 $creator = $adb->query_result($res,0,'smcreatorid'); 735 736 return $creator; 737 } 738 739 /** function used to get the picklist values 740 * @param string $picklist_name - picklist name you want to retrieve from database 741 * return array $picklist_array - all values of the corresponding picklist will be returned as a array 742 */ 743 function get_picklists($picklist_name) 744 { 745 global $adb, $log; 746 $log->debug("Entering into function get_picklists($picklist_name)"); 747 748 $picklist_array = Array(); 749 750 $res = $adb->query("select * from vtiger_".$picklist_name); 751 for($i=0;$i<$adb->num_rows($res);$i++) 752 { 753 $picklist_val = $adb->query_result($res,$i,$picklist_name); 754 $picklist_array[$i] = $picklist_val; 755 } 756 757 $log->debug("Exit from function get_picklists($picklist_name)"); 758 return $picklist_array; 759 } 760 761 /** function to get the attachments of a ticket 762 * @param int $userid - customer id 763 * @param int $ticketid - ticket id 764 * return array $output - This will return all the file details related to the ticket 765 */ 766 function get_ticket_attachments($userid,$ticketid) 767 { 768 769 global $adb; 770 771 $query = "select vtiger_troubletickets.ticketid, vtiger_attachments.* from vtiger_troubletickets inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.crmid = vtiger_troubletickets.ticketid inner join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid where vtiger_troubletickets.ticketid=".$ticketid; 772 $res = $adb->query($query); 773 $noofrows = $adb->num_rows($res); 774 775 for($i=0;$i<$noofrows;$i++) 776 { 777 $filename = $adb->query_result($res,$i,'name'); 778 $filepath = $adb->query_result($res,$i,'path'); 779 780 $fileid = $adb->query_result($res,$i,'attachmentsid'); 781 $filesize = filesize($filepath.$fileid."_".$filename); 782 $filetype = $adb->query_result($res,$i,'type'); 783 784 $filecontents = base64_encode(file_get_contents($filepath.$fileid."_".$filename));//fread(fopen($filepath.$filename, "r"), $filesize)); 785 786 $output[$i]['fileid'] = $fileid; 787 $output[$i]['filename'] = $filename; 788 $output[$i]['filetype'] = $filetype; 789 $output[$i]['filesize'] = $filesize; 790 $output[$i]['filecontents'] = $filecontents; 791 } 792 793 return $output; 794 } 795 796 /** function to add attachment for a ticket ie., the passed contents will be write in a file and the details will be stored in database 797 * @param int $ticketid - ticket id 798 * @param string $filename - file name to be attached with the ticket 799 * @param string $filetype - file type 800 * @param int $filesize - file size 801 * @param string $filecontents - file contents as base64 encoded format 802 * return void 803 */ 804 function add_ticket_attachment($ticketid, $filename, $filetype, $filesize, $filecontents) 805 { 806 global $adb; 807 global $root_directory; 808 809 //decide the file path where we should upload the file in the server 810 $upload_filepath = decideFilePath(); 811 812 $attachmentid = $adb->getUniqueID("vtiger_crmentity"); 813 814 $new_filename = $attachmentid.'_'.$filename; 815 816 $data = base64_decode($filecontents); 817 818 //write a file with the passed content 819 $handle = @fopen($upload_filepath.$new_filename,'w'); 820 fputs($handle, $data); 821 fclose($handle); 822 823 //Now store this file information in db and relate with the ticket 824 $date_var = $adb->formatDate(date('YmdHis')); 825 $description = 'CustomerPortal Attachment'; 826 827 $crmquery = "insert into vtiger_crmentity (crmid,setype,description,createdtime) values('".$attachmentid."','HelpDesk Attachment','".$description."',".$date_var.")"; 828 $crmresult = $adb->query($crmquery); 829 830 $attachmentquery = "insert into vtiger_attachments values(".$attachmentid.",'".$filename."','".$description."','".$filetype."','".$upload_filepath."')"; 831 $attachmentreulst = $adb->query($attachmentquery); 832 833 $relatedquery = $sql1 = "insert into vtiger_seattachmentsrel values('".$ticketid."','".$attachmentid."')"; 834 $relatedresult = $adb->query($relatedquery); 835 836 } 837 838 /* Begin the HTTP listener service and exit. */ 839 $server->service($HTTP_RAW_POST_DATA); 840 841 exit(); 842 843 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |