Insert accounts in Sugar CRM using Codeigniter

Posted by Yash On December - 30 - 2009ADD COMMENTS
//load new database of Sugar CRM as defined in database.php
        $this->db2 = $this->ci->load->database('db_crm', TRUE);
 
        //generate unique id for sugar crm . length:36
        $accounts_id=$this->generateCrmID('accounts');
 
        //insert account into CRM
        $account_data=array(
            'id'=> $accounts_id,
            'name'=> $user_details['first_name'].' '.$user_details['last_name'],
            'date_entered'=> date('Y-m-d h:i:s'),
            'date_modified'=> date('Y-m-d h:i:s'),
            'modified_user_id'=> '417785b3-1644-6586-11f7-4b2a02c9fede',
            'created_by'=> '417785b3-1644-6586-11f7-4b2a02c9fede',
            'description'=> strip_tags($content),
            'deleted'=> 0,
            'assigned_user_id'=> '417785b3-1644-6586-11f7-4b2a02c9fede',
            'account_type'=> 'Customer',
            'industry'=> $user_details['industry'],
            'annual_revenue'=> '',
            'phone_fax'=> '',
            'billing_address_street'=> $user_details['address1']." ".$user_details['address2'],
            'billing_address_city'=> $user_details['city'],
            'billing_address_state'=> $user_details['state'],
            'billing_address_postalcode'=> $user_details['zip'],
            'billing_address_country'=> $user_details['country'],
            'rating'=> '',
            'phone_office'=> $user_details['mobile'],
            'phone_alternate'=> $user_details['phone'],
            'website'=> $user_details['website'],
            'ownership'=> '',
            'employees'=> '',
            'ticker_symbol'=> '',
            'shipping_address_street'=> '',
            'shipping_address_city'=> '',
            'shipping_address_state'=> '',
            'shipping_address_postalcode'=> '',
            'shipping_address_country'=> '',
            'parent_id'=> '',
            'sic_code'=> '',
            'campaign_id'=> '');
 
        $this->db2->insert('accounts',$account_data);
 
        $email_id=$this->generateCrmID('email_addresses');
        $email_data=array(
            'id' => $email_id,
            'email_address' => $user_details['email'] ,
            'email_address_caps' => strtoupper($user_details['email'] ),
            'invalid_email' => 0,
            'opt_out' => 0,
            'date_created' => date('Y-m-d h:i:s'),
            'date_modified' => date('Y-m-d h:i:s'),
            'deleted' => 0
        );
        $this->db2->insert('email_addresses',$email_data);
 
        $email_addr_id=$this->generateCrmID('email_addr_bean_rel');
        $email_addr_bean_rel_data=array(
            'id' => $email_addr_id,
            'email_address_id' => $email_id,
            'bean_id' => $accounts_id,
            'bean_module' => 'Accounts',
            'primary_address' => 0,
            'reply_to_address' => 0,
            'date_created' => date('Y-m-d h:i:s'),
            'date_modified' => date('Y-m-d h:i:s'),
            'deleted' => 0,
        );
        $this->db2->insert('email_addr_bean_rel',$email_addr_bean_rel_data);
 
        //load default database
        $this->ci->load->database('default', TRUE);

Dependent function(s)

function generateCrmID($condition)
    {
 
        do
        {
            $crm_id = "CONX".random_string('unique');
 
            switch($condition)
            {
                case 'accounts':
                    $query = $this->ci->db->get_where('accounts', array('id' => $crm_id));
                    break;
                case 'email_addresses':
                    $query = $this->ci->db->get_where('email_addresses', array('id' => $crm_id));
                    break;
                case 'email_addr_bean_rel':
                    $query = $this->ci->db->get_where('email_addresses', array('id' => $crm_id));
                    break;
                default:
                    $query = $this->ci->db->get_where('accounts', array('id' => $crm_id));
                    break;
            }
            //ticketmaskid FROM '". TABLE_PREFIX ."' WHERE '' = '". $dbCore->escape() ."';");
            $id=$this->ci->db->count_all();
 
        } while ($id!=0);
 
        return $crm_id;
 
    }

Popularity: 71% [?]

Insert ticket in Support Suite using CodeIgniter

Posted by Yash On December - 30 - 2009ADD COMMENTS
   // Insert the Actual Record
        $ticket_data=array(
            'ticketid'=>'',
            'ticketmaskid'=>$ticketmaskid ,
            'departmentid'=>1 ,
            'ticketstatusid'=>1 ,
            'priorityid'=> 1,
            'emailqueueid'=>0 ,
            'userid'=>68 ,
            'staffid'=>2,
            'ownerstaffid'=>2,
            'assignstatus'=>1,
            'fullname'=>'someva' ,
            'email'=>$user_details['email'] ,
            'lastreplier'=>'someva' ,
            'replyto'=>$user_details['email'] ,
            'subject'=>'New Account is registered' ,
            'dateline'=>now() ,
            'lastactivity'=>now() ,
            'laststaffreplytime'=>now() ,
            'slaplanid'=>1 ,
            'duetime'=>0 ,
            'totalreplies'=>0 ,
            'ipaddress'=>'' ,
            'flagtype'=> 0,
            'hasnotes'=> 0,
            'hasattachments'=> 0,
            'isemailed'=> 0,
            'edited'=> 0,
            'editedbystaffid'=> 0,
            'editeddateline'=> 0,
            'creator'=> 1,
            'charset'=>'UTF-8' ,
            'transferencoding'=>'' ,
            'timeworked' =>0 ,
            'dateicon' =>0,
            'lastpostid'=>0,
            'firstpostid'=>0,
            'tgroupid'=>1 ,
            'messageid' =>$messageid ,
            'escalationruleid'=>0 ,
            'hasdraft'=>0 ,
            'hasbilling' =>0 ,
            'isphonecall' =>0 ,
            'isescalated'=>0 ,
            'phoneno'=>'' ,
            'autoclosetimeline' =>0 ,
            'islabeled' =>0 ,
            'lastuserreplytime' => now(),
            'escalatedtime' =>0 ,
            'followupcount'=>0 );
 
        $this->db1->insert('swtickets',$ticket_data);
        $ticketid=$this->db1->insert_id();
 
        $content="<p>Hi,</p>";
        $content.="<p>New account is registered with following details:</p>";
        $content.="<p> Full Name: ".$user_details['first_name']." ".$user_details['last_name'];
        $content.="</p><p> Email: ".$user_details['email']." </p>";
        $content.="<p> ".$this->get_orders()." </p>";
        $content.="<p></p>";
 
        $post_data=array(
            'ticketpostid'=>'' ,
            'ticketid'=>$ticketid ,
            'dateline'=>now() ,
            'userid'=>68 ,
            'fullname'=> 'someva',
            'email'=>$user_details['email'] ,
            'emailto'=>'' ,
            'subject'=>'New Account Registration' ,
            'ipaddress'=>'' ,
            'hasattachments'=>0 ,
            'edited'=>0 ,
            'editedbystaffid'=>0 ,
            'editeddateline'=>0 ,
            'creator'=>1 ,
            'ishtml'=>1 ,
            'isemailed'=>0 ,
            'staffid'=>2 ,
            'contents'=> $content,
            'contenthash'=>md5($content) ,
            'subjecthash'=>md5('New Account Registration')
        );
 
        $this->db1->insert('swticketposts',$post_data);
        $ticketpostid=$this->db1->insert_id();
 
 
 
        $ticket_message_data=array(
            'ticketmessageid'=>'',
            'messageid'=>$messageid ,
            'ticketid'=>$ticketid ,
            'ticketpostid'=>$ticketpostid ,
            'dateline' => now());
 
        $this->db1->insert('swticketmessageids',$ticket_message_data);
        $ticketmessageid=$this->db1->insert_id();
 
        //load default database
        $this->ci->load->database('default', TRUE);

Dependent functions

 /**
     * Generates a Random Message ID
     */
    function generateRandomMessageID()
    {
        srand((double)microtime()*10000000);
        $messageid = base_convert(time(), 10, 36).".". base_convert(rand(), 10, 36);
        return $messageid;
 
    }
    /**
     * Generate a random Ticket Mask
     */
    function generateTicketMask()
    {
 
    //        $id=100;
        do
        {
 
            $prefix = strtoupper(chr(mt_rand(65,90)) . chr(mt_rand(65,90)) . chr(mt_rand(65,90)));
 
            $ticketmaskid = $prefix . "-" . mt_rand(100000,999999);
            //$_maskcheck =
 
            $query = $this->ci->db->get_where('swtickets', array('ticketmaskid' => $ticketmaskid));
            //ticketmaskid FROM '". TABLE_PREFIX ."' WHERE '' = '". $dbCore->escape() ."';");
            $id=$this->ci->db->count_all();
 
        } while ($id!=0);
 
        return $ticketmaskid;
 
    }

Popularity: 61% [?]

SEO based urls : CodeIgniter routes

Posted by Yash On December - 30 - 2009ADD COMMENTS

You can use this code for SEO urls

 
//this section enables you to use some controllers 
$route['admin/(:any)'] = "admin/$1";    
$route['contact/(:any)'] = "contact/$1";
$route['auth/(:any)'] = "auth/$1";
$route['testimonials/(:any)'] = "testimonials/$1";
 
//else everything in url will handle by this pro controller's index function
$route['(:any)'] = "pro/index";

May be when you need this you can understand this logic. crazy na ;)

Popularity: 73% [?]

Automatic Config BASE URL in CodeIgniter

Posted by Yash On December - 24 - 2009ADD COMMENTS

Change $config['base_url'] with this.
This is one time set config system for all sites and urls.
In application/config folder open config.php
Find this

$config['base_url']='http://example.com';

and replace with this

 
$config['base_url'] =  ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ?  "https" : "http");
$config['base_url'] .=  "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .=  str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

Popularity: 76% [?]

Insert user in Support suite using CodeIginiter

Posted by Yash On December - 15 - 2009ADD COMMENTS

Paste following code in end of database.php located in config folder

$db['db_support']['hostname'] = "localhost";
$db['db_support']['username'] = "dbname";
$db['db_support']['password'] = "password";
$db['db_support']['database'] = "supportsuite_databasename";
$db['db_support']['dbdriver'] = "mysql";
$db['db_support']['dbprefix'] = "";
$db['db_support']['pconnect'] = TRUE;
$db['db_support']['db_debug'] = TRUE;
$db['db_support']['cache_on'] = FALSE;
$db['db_support']['cachedir'] = "";
$db['db_support']['char_set'] = "utf8";
$db['db_support']['dbcollat'] = "utf8_general_ci";

and use this one where ever you want.

 
        $this->db->select("users.*", FALSE);  //these are tables where you have original codeigniter based users
        $this->db->select("user_profile.*", FALSE);
        $this->db->join('user_profile', "user_profile.user_id = users.id");
        $this->db->where('users.id',$user_id);
        $this->db->order_by("users.id", "ASC");
        $query = $this->db1->get();
        //print_r( $query->row_array());
 
       $this->db1 = $this->load->database('db_support', TRUE);
        $this->db1->from('swusers');
        $this->db1->where('swusers');
        $query = $this->db1->get();
        //print_r( $query->row_array());
 
        $user=array(
            'userid' =>'',
            'usergroupid' =>3,
            'fullname' =>'',
            'phone' =>'',
            'userpassword' =>'',
            'userpasswordtxt' =>'',
            'dateline' =>'',
            'lastvisit' =>'',
            'lastactivity' =>'',
            'enabled' =>'',
            'loginapi_moduleid' =>'',
            'loginapi_userid' =>'',
            'languageid' =>'',
            'timezoneoffset' =>'',
            'enabledst' =>'',
            'useremailcount' =>'',
            'allowemail' =>'',
            'slaplanid' =>'',
            'slaexpiry' =>'',
            'ismanager' =>''
        );
 
        $this->db1->insert('swusers',$user);
 
        $user_email=array(
            'useremailid'=> '',
            'userid' => $this->db1->insert_id(),
            'email' => 'isprimary'
        );
 
        $this->db1->insert('swusers',$user);

Popularity: 79% [?]

Use QColor from getColor on QLabel and QTextbox

Posted by Yash On December - 12 - 2009ADD COMMENTS
//To use color on text and label 
//Simple sample :)
QColor color = QColorDialog::getColor(QColor(ui->backgroundColorPickerText->text()), this);
   if(color.isValid())
    {
 
        QPixmap pix(21, 21);
        pix.fill(color);
 
        ui->backgroundColorPickerLabel->setPixmap(pix);
        ui->backgroundColorPickerText->setText(color.name());
    }

Popularity: 56% [?]

//create a custom dialog box with multi line input
void MainWindow::createMultilineInput()
{
//class variable    
dlgMultiLine =    new QDialog(this);
 
//local variable
    QGridLayout *gridLayout = new QGridLayout(dlgMultiLine);
 
//class variable
    txtMultiline = new QPlainTextEdit();
 
    txtMultiline->setObjectName(QString::fromUtf8("txtMultiline"));
    gridLayout->addWidget(txtMultiline, 0, 0, 1, 1);
    QDialogButtonBox *buttonBox = new QDialogButtonBox();
    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
    buttonBox->setOrientation(Qt::Horizontal);
    buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
 
    gridLayout->addWidget(buttonBox, 1, 0, 1, 1);
 
    connect(buttonBox,SIGNAL(accepted()),this,SLOT(on_acceptLoadHtml()));
    connect(buttonBox,SIGNAL(rejected()),this,SLOT(on_rejectLoadHtml()));
 
    dlgMultiLine->show();
}

Popularity: 61% [?]

Sometime you need to show data in external window with custom widget(s). This little code will help you.

function showCustomWidget() {
 
 QDialog *dlgMultiLine =    new QDialog();
 QGridLayout *gridLayout = new QGridLayout(dlgMultiLine);
 QPlainTextEdit *txtMultiline = new QPlainTextEdit();
 
 txtMultiline->setPlainText(this->toPlainText());
 
 gridLayout->addWidget(txtMultiline, 0, 0, 1, 1);
 dlgMultiLine->show();
 
}

Popularity: 54% [?]

// Display a dialog to the user to choose his music directory
      QString directory_path = QFileDialog::getExistingDirectory(this, tr("Select your music directory"), QDir::currentPath());
 
     // Then create an instance of our QDirIterator, which takes as parameters
     // the directory, a QDir filter and an option flag which the QDirIterator is told
     // to go on the subdirectories also.
     // I have combined the QDir filters to list files and not to get the symbolic links (shortcuts in Windows).
 
     QDirIterator directory_walker(directory_path, QDir::Files | QDir::NoSymLinks, QDirIterator::Subdirectories);
 
    // QDirIterator object has a boolean method called hasNext() which returns true
    // if the directory have more files, false otherwise and based on that information,
    // we can write a while loop like the one below
 
    while(directory_walker.hasNext())
    {
          // then we tell our directory_walker object to explicitly take next element until the loop finishes
          directory_walker.next();
 
         // I want to list just mp3 files!
         //if(directory_walker.fileInfo().completeSuffix() == "css")
                 // then we take a filename and display it to a listWidget like the code below:
                ui->listWidget->addItem(directory_walker.fileName());
    }

Original link : phalanx.spartansoft.org/2009/01/20/getting-all-files-from-subdirectories-recursively-with-c-using-qt-framework/

Popularity: 57% [?]

A Tip in codeigniter to join two tables have same coloum name id
 $this->ci->db->select("users.*", FALSE);
 $this->ci->db->select("user_profile.*", FALSE);
 $this->ci->db->from("users");
 $this->ci->db->join("user_profile", "user_profile.user_id = users.id",'inner');
 $this->ci->db->where(array('users.id'=>$user_id), NULL, FALSE);
Users table has id and other table User_profile have id and user_id now users's id and user_profile's user_id have a foreign key relationship.
user_id from User_profile is foriegn key of users'id . Therefore both entries in different tables are same i.e. user_profile's user_id amd users's id are same. You will receieve an array like this with ofcourse more fields. ID and User_ID is merged into user_id and id of array contains id of user_profile table.

now

example:

  [id] => 34
  [user_id] => 41

Popularity: 69% [?]

TAG CLOUD

About Me

This is my life without coffee :)

Twitter

    Photos

    codemonkeyOutsideInsideIan Corey in the hundred-year-old elevator at Nuthouse HardwareIan and Kevin set up a shootKevin Hoffman in the hundred-year-old elevator at Nuthouse HardwareIan and Kevin set up a shootIan sets up a shot