Location: PHPKode > projects > SHINE Live Help > shine-1.1.0/crm_archive.php
<?php
//===========================================================================
//* --    ~~               Shine Live Help                ~~    -- *
//===========================================================================
//           URL:   http://www.iradeon.com/shine.html    EMAIL: hide@address.com
//         Copyright (C) 2006 iRadeon Group Inc. (http://www.iradeon.com )
//             Shine is a derivative of Crafty Syntax Live Help,
//                     copyright (C) Eric Gerdes 2003--2006
// --------------------------------------------------------------------------
// LICENSE:
//     This program is free software; you can redistribute it and/or
//     modify it under the terms of the GNU General Public License
//     as published by the Free Software Foundation; 
//     This program is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
//
//     You should have received a copy of the GNU General Public License
//     along with this program in a file named LICENSE.txt .
// --------------------------------------------------------------------------  
require_once("admin_common.php");
require_once('../sugarcrm-4.2.1a-20060816/sugar_version.php');
require_once('../sugarcrm-4.2.1a-20060816/include/nusoap/nusoap.php');

validate_session($identity);
?>
<head>
<link title="new" rel="stylesheet" href="style.css" type="text/css">
<title>Archive Records to CRM</title> 
</head>
<body marginheight="5" marginwidth="5" bgcolor="FDFDFD"> 
<script type="text/javascript"> 
 
var CRMddl = "" 
if (CRMddl = "account") 
 { 
//window.open("http://www.google.com","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400") 
 } 
else if (CRMddl = "case") 
 { 
//window.open("http://www.yahoo.com","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400") 
 } 
else if (CRMddl = "contact") 
 { 
//window.open("http://login.sbcglobal.net","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400") 
 } 
else (CRMddl = "lead") 
 { 
//window.open("http://www.myspace.com","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400") 
 } 
 
</script> 
<form name="search_crm" action="crm_archive.php" method="post">
<input type="hidden" name="action" value="search">
<p>Find CRM records using the search fields below.</p> 
<tr>
   <input type="text" name="search_text" size=30 value=""><input type=submit value="Search CRM"> 
</tr>
<!-- Need code for Search above --> 
 
    <br> 
    <table cellspacing=15 width=330><tbody> 
    <tr> 
    	<td > 
    		<input type="checkbox" name="search_all" id="all" value="ON" checked /> 
    		<label for="all">All</label> 
    	</td> 
    		<td width="95"><input type="checkbox" name="search_accounts" id="accounts" value="ON" /> 
    		<label for="accounts">Accounts</label> 
    	</td> 
    	<td width="116"> 
    		<input type="checkbox" name="search_cases" id="cases" value="ON" /> 
   			<label for="cases">Cases</label>
            </td>
     </tr>
     <tr>
        <td></td>
        <td width=> 
      		<input type="checkbox" name="search_leads" id="leads" value="ON" > 
   			<label for="leads">Leads</label> 
   		</td> 
    	<td width="116"> 
    		<input type="checkbox" name="search_contacts" id="contacts" value="ON" /> 
    		<label for="contacts">Contacts</label> 
    	</td> 
    </tr> 
</table> 
</form>
 
<?php # Need to code the drop down list above to open new window for appropriate selection. Either through a Create button or by clicking the selection in the drop downlist. ?>
<?php #onChange="document.getElementById('selPageMySchedule').value = 1;uniform.submit();" ?>
 
<form name="archive_crm" action="crm_archive.php" method="post">
<input type="hidden" name="action" value="archive">
<?php
/* If the op has clicked on the search button, we want to display a list of matching 
   records. */
$found_entry = 0;
$html = '<input type="hidden" name="visitor_sessionid" value="'.$UNTRUSTED['visitor_sessionid'].'">';
$html .= '<select name="account_ids" size="15">';
if (!(empty($UNTRUSTED['action'])) && ($UNTRUSTED['action'] === 'search')) {
    // Connect to sugarsoap
    $soapclient = new nusoapclient('http://chat.iradeon.info/sugarcrm/soap.php');
    $soap_session_data = 
        $soapclient->call('login', array('user_auth' => array('user_name'=>'dk', 'password'=>md5('dk'))));

    if ( !empty($UNTRUSTED['search_accounts']) || !empty($UNTRUSTED['search_all']) ) {
        $entry_list['accounts'] = 
            $soapclient->call('get_entry_list',
                    array('session'=>$soap_session_data['id'],
                        'module_name'=>'Accounts',
                        'query'=>"accounts.email1 LIKE '".$UNTRUSTED['search_text']."' OR accounts.name LIKE '".$UNTRUSTED['search_text']."'",
                        'order_by'=>'accounts.name' ));
    } 
    if ( !empty($UNTRUSTED['search_cases']) || !empty($UNTRUSTED['search_all']) ) {
        $entry_list['cases'] = 
            $soapclient->call('get_entry_list',
                    array('session'=>$soap_session_data['id'],
                        'module_name'=>'Cases',
                        'query'=>"cases.account_name LIKE '".$UNTRUSTED['search_text']."'",
                        'order_by'=>'cases.name' ));
    } 
    if ( !empty($UNTRUSTED['search_leads']) || !empty($UNTRUSTED['search_all']) ) {
        $entry_list['leads'] = 
            $soapclient->call('get_entry_list',
                    array('session'=>$soap_session_data['id'],
                        'module_name'=>'Leads',
                        'query'=>"leads.email1 LIKE '".$UNTRUSTED['search_text']."' OR leads.account_name LIKE '".$UNTRUSTED['search_text']."'",
                        'order_by'=>'leads.account_name' ));
    } 
    if (!empty($UNTRUSTED['search_contacts']) || !empty($UNTRUSTED['search_all'])) {
        $entry_list['contacts'] = 
            $soapclient->call('get_entry_list',
                    array('session'=>$soap_session_data['id'],
                        'module_name'=>'Contacts',
                        'query'=>"contacts.email1 LIKE '".$UNTRUSTED['search_text']."'",
                        'order_by'=>'contacts.last_name' ));
    }
    foreach( $entry_list as $module_name => $sugar_entry ) {
        if ($sugar_entry['result_count'] = 0) 
            continue;
        foreach ($sugar_entry['entry_list'] as $entry) {
            /* We are going to pass the sugar id and visitor id delimited by a '$' */
            $html .= "<option value='".$entry['id']."$".$UNTRUSTED['visitor_sessionid']."'>";
            foreach($entry['name_value_list'] as $namevalue) {
                if($namevalue['name'] === 'first_name') {
                    $first_name = $namevalue['value'];
                }
                if($namevalue['name'] === 'last_name') {
                    $last_name = $namevalue['value'];
                }
                if($namevalue['name'] === 'name' || $namevalue['name'] === 'account_name') {
                    $account_name = $namevalue['value'];
                }
            }
            $html .= "Name: ".$first_name ." ".$last_name. "   Account: ".$account_name."</option>\n";
        }
    }



//    $html .= '<option value="id"> A search for '.$UNTRUSTED['search_text'].' has been performed. </option>';
    $soapclient->call('logout', array('session'=>$soap_session_data['id']));
}
print $html;
print "</select>";
if (!(empty($UNTRUSTED['action'])) && ($UNTRUSTED['action'] === 'archive')) {
    /* Split up the sugarcrm id and the shine id */
    $account_ids = $UNTRUSTED['account_ids'];
    list($sugar_id, $shine_id) = split('\$', $account_ids);
    /* connect to soap */
    $soapclient = new nusoapclient('http://chat.iradeon.info/sugarcrm/soap.php');
    $soap_session_data = 
        $soapclient->call('login', array('user_auth' => array('user_name'=>'dk', 'password'=>md5('dk'))));
    /* Grab the convo data from shine */
    $sqlquery = "SELECT * FROM livehelp_transcripts WHERE sessionid='".$shine_id."' order by recno desc";
    $transcript_data = $mydatabase->query($sqlquery);
    if ($transcript_data->numrows() == 0) {
        print "Error retrieving transcript data from shine.";
    }
    $transcript = $transcript_data->fetchrow(DB_FETCHMODE_ASSOC);
    print $transcript['transcript'];

    ## Convert transcript to plain text
    require_once('html2text.inc');
    $htt = new Html2Text($transcript['transcript'], 80);
    $text = $htt->convert();
    /* stick the correct data in $transcript into a name_value_list */
    $transcript_name_value_list = array(
        array( 
            'name' => 'description',
            'value' => $text ),
        array( 
            'name' => 'parent_id',
            'value' => $sugar_id),
        array( 
            'name' => 'parent_type',
            'value' => 'Leads'),
        array( 
            'name' => 'name',
            'value' => 'Shine Chat Dialog')
    );
    $ret = $soapclient->call('set_entry',
            array('session' => $soap_session_data['id'],
                'module_name' => 'Notes',
                'name_value_list' => $transcript_name_value_list)
            );
    if ($ret['error']['number'] != 0) {
        print "There was an error setting the note.";
        print $ret['error']['name'];
        print $ret['error']['description'];
    }

    $soapclient->call('logout', array('session'=>$soap_session_data['id']));

}

?>
<input type="submit" name="archive" value="Archive">
</form>
<form name="create_crm" action="crm_create.php" method="post">
<table width="330"> 
	<tr> 
	</tr>
    <tr>
    <!-- Need code for the All checkbox above to check remaining boxes -->
  
        <tr>
             <td align="center">
                <input align="right" type="Submit" value="CreateNew"> 
      
                <select align="left" name="createcrm">
                       <option value=""></A>
                       <option value="account">Account</A>
                       <option value="case">Case</A>
                       <option value="contact">Contact</A>
                       <option value="lead">Lead</A>
                   </select>
              </td>
                
      </tr>            

                                                                                                                                                                         
</table> 
</form> 
 
 
</body> 
 
</html>
Return current item: SHINE Live Help