Create user in vTiger 6 programmatically - php

I want to create user in vTiger programmatically and I need to understand what happens in the background when we add a user from UI. If I can understand the flow I can replicate it by writing the code.
Or is there a API for it?

Here is the code:
require_once 'modules/Users/Users.php';
$user_email='new_user#yourdomain.com';
$role_id_to_assign='H1';
$user = new Users();
$user->column_fields["last_name"] = 'John';
$user->column_fields["user_name"] = 'Mee';
$user->column_fields["status"] = 'Active';
$user->column_fields["is_admin"] = 'off';
$user->column_fields["user_password"] = $user_password;
$user->column_fields["tz"] = 'Europe/Berlin';
$user->column_fields["holidays"] = 'de,en_uk,fr,it,us,';
$user->column_fields["workdays"] = '0,1,2,3,4,5,6,';
$user->column_fields["weekstart"] = '1';
$user->column_fields["namedays"] = '';
$user->column_fields["currency_id"] = 1;
$user->column_fields["reminder_interval"] = '1 Minute';
$user->column_fields["reminder_next_time"] = date('Y-m-d H:i');
$user->column_fields["date_format"] = 'dd-mm-yyyy';
$user->column_fields["hour_format"] = 'am/pm';
$user->column_fields["start_hour"] = '08:00';
$user->column_fields["end_hour"] = '23:00';
$user->column_fields["imagename"] = '';
$user->column_fields["internal_mailer"] = '1';
$user->column_fields["activity_view"] = 'This Week';
$user->column_fields["lead_view"] = 'Today';
$user->column_fields["email1"] = $user_email;
$user->column_fields["roleid"] = $role_id_to_assign;
$new_user_id = $user->save("Users");
It will return the id of the new User. The User will be assigned to the Role CEO ('H1').

Related

How can i export & Import custom modules as Package using PHP Script (Vtlib Function) from my CRM vtiger 7

I hope all of you are doing well.
I have created a custom module used this script.we have run this script in root folder.All field are working fine and list view also perfect.
```
<?php
include_once 'vtlib/Vtiger/Module.php';
include_once 'vtlib/Vtiger/Package.php';
include_once 'includes/main/WebUI.php';
include_once 'include/Webservices/Utils.php';
$Vtiger_Utils_Log = true;
$MODULENAME = 'Laptop';
$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
echo "Module already present - choose a different name.";
} else {
$moduleInstance = new Vtiger_Module();
$moduleInstance->name = $MODULENAME;
$moduleInstance->parent= 'Tools';
$moduleInstance->save();
// Schema Setup
$moduleInstance->initTables();
// Field Setup
$block = new Vtiger_Block();
$block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
$moduleInstance->addBlock($block);
$blockcf = new Vtiger_Block();
$blockcf->label = 'LBL_CUSTOM_INFORMATION';
$moduleInstance->addBlock($blockcf);
// Text Area1 Item_Name
$itemName = new Vtiger_Field();
$itemName->name = 'itemname';
$itemName->label= 'Item Name';
$itemName->uitype= 1;
$itemName->column = $itemName->name;
$itemName->columntype = 'VARCHAR(100)';
$itemName->typeofdata = 'V~M';
$block->addField($itemName);
// Text Area2 Item_Deatils
$itemdeatils = new Vtiger_Field();
$itemdeatils->name = 'itemdeatils';
$itemdeatils->label= 'Item Deatils';
$itemdeatils->uitype= 1;
$itemdeatils->column = $itemdeatils->name;
$itemdeatils->columntype = 'VARCHAR(100)';
$itemdeatils->typeofdata = 'V~O';
$block->addField($itemdeatils);
$moduleInstance->setEntityIdentifier($itemdeatils);
// Text Area3 Item_Company.
$companyname = new Vtiger_Field();
$companyname->name = 'companyname';
$companyname->label= 'Company Name.';
$companyname->uitype= 15;
$companyname->column = $companyname->name;
$companyname->columntype = 'VARCHAR(100)';
$companyname->typeofdata = 'V~O';
$block->addField($companyname);
$companyname->setPicklistValues( Array ('Sumsung','HP','Dell', 'Lenovo','Apple') );
$description = new Vtiger_Field();
$description->name = 'description';
$description->label= 'Description';
$description->uitype= 19;
$description->column = 'description';
$description->table = 'vtiger_crmentity';
$blockcf->addField($description);
// Recommended common fields every Entity module should have (linked to core table)
$mfield1 = new Vtiger_Field();
$mfield1->name = 'assigned_user_id';
$mfield1->label = 'Assigned To';
$mfield1->table = 'vtiger_crmentity';
$mfield1->column = 'smownerid';
$mfield1->uitype = 53;
$mfield1->typeofdata = 'V~M';
$block->addField($mfield1);
$mfield2 = new Vtiger_Field();
$mfield2->name = 'createdtime';
$mfield2->label= 'Created Time';
$mfield2->table = 'vtiger_crmentity';
$mfield2->column = 'createdtime';
$mfield2->uitype = 70;
$mfield2->typeofdata = 'DT~O';
$mfield2->displaytype= 2;
$block->addField($mfield2);
$mfield3 = new Vtiger_Field();
$mfield3->name = 'modifiedtime';
$mfield3->label= 'Modified Time';
$mfield3->table = 'vtiger_crmentity';
$mfield3->column = 'modifiedtime';
$mfield3->uitype = 70;
$mfield3->typeofdata = 'DT~O';
$mfield3->displaytype= 2;
$block->addField($mfield3);
/* NOTE: Vtiger 7.1.0 onwards */
$mfield4 = new Vtiger_Field();
$mfield4->name = 'source';
$mfield4->label = 'Source';
$mfield4->table = 'vtiger_crmentity';
$mfield4->displaytype = 2; // to disable field in Edit View
$mfield4->quickcreate = 3;
$mfield4->masseditable = 0;
$block->addField($mfield4);
$mfield5 = new Vtiger_Field();
$mfield5->name = 'starred';
$mfield5->label = 'starred';
$mfield5->table = 'vtiger_crmentity_user_field';
$mfield5->displaytype = 6;
$mfield5->uitype = 56;
$mfield5->typeofdata = 'C~O';
$mfield5->quickcreate = 3;
$mfield5->masseditable = 0;
$block->addField($mfield5);
$mfield6 = new Vtiger_Field();
$mfield6->name = 'tags';
$mfield6->label = 'tags';
$mfield6->displaytype = 6;
$mfield6->columntype = 'VARCHAR(1)';
$mfield6->quickcreate = 3;
$mfield6->masseditable = 0;
$block->addField($mfield6);
/* End 7.1.0 */
// Filter Setup
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$moduleInstance->addFilter($filter1);
$filter1->addField($itemName);
$filter1->addField($itemdeatils, 1);
$filter1->addField($companyname, 2);
$filter1->addField($mfield1, 3);
// Sharing Access Setup
$moduleInstance->setDefaultSharing('Private');
// Webservice Setup
$moduleInstance->initWebservice();
$targetpath = 'modules/' . $moduleInstance->name;
if (! is_file($targetpath)) {
mkdir($targetpath);
$templatepath = 'vtlib/ModuleDir/6.0.0';
$moduleFileContents = file_get_contents($templatepath . '/ModuleName.php');
$replacevars = array(
'ModuleName' => $moduleInstance->name,
'<modulename>' => strtolower($moduleInstance->name),
'<entityfieldlabel>' => $field1->label,
'<entitycolumn>' => $field1->column,
'<entityfieldname>' => $field1->name
);
foreach ($replacevars as $key => $value) {
$moduleFileContents = str_replace($key, $value, $moduleFileContents);
}
file_put_contents
($targetpath . '/' . $moduleInstance->name . '.php',$moduleFileContents);
}
if (! file_exists('languages/en_us/ModuleName.php')) {
$ModuleLanguageContents = file_get_contents
($templatepath . '/languages/en_us /ModuleName.php');
$replaceparams = array(
'Module Name' => $moduleInstance->name,
'Custom' => $moduleInstance->name,
'ModuleBlock' => $moduleInstance->name,
'ModuleFieldLabel Text' => $field1->label
);
foreach ($replaceparams as $key => $value) {
$ModuleLanguageContents = str_replace($key, $value, $ModuleLanguageContents);
}
$languagePath = 'languages/en_us';
file_put_contents
($languagePath . '/' . $moduleInstance->name . '.php',$ModuleLanguageContents);
}
}
Settings_MenuEditor_Module_Model::addModuleToApp
($moduleInstance->name, $moduleInstance->parent);
?>
```
how can i export & Import custom modules as Package using PHP Script (Vtlib Function) from my CRM vtiger 7, Please help me.
I was stuck on How to create a custom module in Vtiger using VTlib library. The code you shared is perfect for creating custom module in vtiger.
To Export your custom module in vtiger, you need to run the code below -
require_once('vtlib/Vtiger/Package.php');
require_once('vtlib/Vtiger/Module.php');
$package = new Vtiger_Package();
$package->export(
Vtiger_Module::getInstance('Payslip'),
'test/vtlib',
'Payslip-Export.zip',
true
);
Don't forget to change the module name

Product id (multisite setup)

We are building a script that makes an xml export of orders. In the export, we need to get the EAN code of the product that has been ordered. Currently we use WooCommerce to get the product info, and get the _sku from there.
However, we notice something is going wrong with our multisite setup.
When a product is ordered from site B, we sometimes are unable to get the EAN code of the ordered product, or get a wrong EAN code.
This because if we use our script and ask WooCommerce -> getOrder -> getItems, we get the product id's from site A, not site B. So when we try to get the _sku info from an ordered item, it's looking for the wrong product.
How can we make sure that with our script, it knows what _sku to take when we get our order information so that it doesn't matter which site the order came from, the order information is always correct?
function bol_2020_custom_process_order_manual($order_id) {
global $voorletters;
$order = new WC_Order( $order_id );
// $myuser_id = (int)$order->user_id;
// $user_info = get_userdata($myuser_id);
// $customer = new WC_Customer($order_id);
$items = $order->get_items();
$xml_order_id = $order_id;
$xml_ORDER_DATE = date('Y-m-d');
$xml_DELIVERY_START_DATE = '2017-09-07';
$xml_DELIVERY_END_DATE = '2017-09-08';
$xml_SUPPLIER_NAME = 'DOMAINNAME.nl';
$xml_SUPPLIER_NAME2 = '';
$xml_SUPPLIER_NAME3 = '';
$xml_SUPPLIER_STREET = '**** 71A';
$xml_SUPPLIER_ZIP = '******';
$xml_SUPPLIER_CITY = '********';
$xml_SUPPLIER_COUNTRY = 'NL';
$xml_BUYUR_NAME = get_post_meta($order_id,'_shipping_first_name',true).' '.get_post_meta($order_id,'_shipping_last_name',true);
$xml_BUYUR_NAME2 = get_post_meta($order_id,'_shipping_company',true);
$xml_BUYUR_NAME3 = '';
$xml_BUYUR_STREET = get_post_meta($order_id,'_shipping_address_1',true).' '.get_post_meta($order_id,'_shipping_address_2',true);
$xml_BUYUR_ZIP = get_post_meta($order_id,'_shipping_postcode',true);
$xml_BUYUR_CITY = get_post_meta($order_id,'_shipping_city',true);
$xml_BUYUR_COUNTRY = get_post_meta($order_id,'_shipping_country',true);
$imp = new DOMImplementation;
$dtd = $imp->createDocumentType('ORDER', '', 'openTRANS_ORDER_1_0.dtd');
$dom = $imp->createDocument("", "", $dtd);
$dom->encoding = 'UTF-8';
$root = $dom->appendChild($root = $dom->createElement('ORDER'));
$order_version = $root->appendChild($dom->createAttribute('version'));
$order_version->value = '1.0';
$order_type = $root->appendChild($dom->createAttribute('type'));
$order_type->value = 'standard';
$root->appendChild($client = $dom->createElement('ORDER_HEADER'));
$order_info = $client->appendChild($dom->createElement('ORDER_INFO'));
$order_info->appendChild($ORDER_ID = $order_info->appendChild($dom->createElement('ORDER_ID')));
$ORDER_ID->appendChild($dom->createTextNode($voorletters.$xml_order_id));
$order_info->appendChild($ALT_CUSTOMER_ORDER_ID = $order_info->appendChild($dom->createElement('ALT_CUSTOMER_ORDER_ID')));
$ALT_CUSTOMER_ORDER_ID->appendChild($dom->createTextNode(''));
$order_info->appendChild($ORDER_DATE = $order_info->appendChild($dom->createElement('ORDER_DATE')));
$ORDER_DATE->appendChild($dom->createTextNode($xml_ORDER_DATE));
$DELIVERY_DATE = $order_info->appendChild($order_info->appendChild($dom->createElement('DELIVERY_DATE')));
$DELIVERY_DATE_ATT = $DELIVERY_DATE->appendChild($dom->createAttribute('type'));
$DELIVERY_DATE_ATT->value = 'fixed';
$DELIVERY_START_DATE = $DELIVERY_DATE->appendChild($dom->createElement('DELIVERY_START_DATE'));
$DELIVERY_START_DATE->appendChild($dom->createTextNode($xml_DELIVERY_START_DATE));
$DELIVERY_END_DATE = $DELIVERY_DATE->appendChild($dom->createElement('DELIVERY_END_DATE'));
$DELIVERY_END_DATE->appendChild($dom->createTextNode($xml_DELIVERY_END_DATE));
$ORDER_PARTIES = $order_info->appendChild($order_info->appendChild($dom->createElement('ORDER_PARTIES')));
$BUYER_PARTY = $ORDER_PARTIES->appendChild($dom->createElement('BUYER_PARTY'));
$PARTY_ID = $BUYER_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID_ = $PARTY_ID->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID__ATT = $PARTY_ID_->appendChild($dom->createAttribute('type'));
$PARTY_ID__ATT->value = 'ILN';
//$PARTY_ID_->appendChild($dom->createTextNode('4317784032988'));
$PARTY_ID_->appendChild($dom->createTextNode('4317784044110'));
$SUPPLIER_PARTY = $ORDER_PARTIES->appendChild($dom->createElement('SUPPLIER_PARTY'));
$PARTY_ID = $SUPPLIER_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID_ = $PARTY_ID->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID__ATT = $PARTY_ID_->appendChild($dom->createAttribute('type'));
$PARTY_ID__ATT->value = 'ILN';
$PARTY_ID_->appendChild($dom->createTextNode('4317784000000'));
$SHIPMENT_PARTIES = $ORDER_PARTIES->appendChild($dom->createElement('SHIPMENT_PARTIES'));
$DELIVERY_PARTY = $SHIPMENT_PARTIES->appendChild($dom->createElement('DELIVERY_PARTY'));
$PARTY = $DELIVERY_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID = $PARTY->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID_ATT = $PARTY_ID->appendChild($dom->createAttribute('type'));
$PARTY_ID_ATT->value = 'supplier_specific';
$PARTY_ID->appendChild($dom->createTextNode(''));
$ADDRESS = $PARTY->appendChild($dom->createElement('ADDRESS'));
$NAME = $ADDRESS->appendChild($dom->createElement('NAME'));
$NAME->appendChild($dom->createTextNode($xml_SUPPLIER_NAME));
$NAME2 = $ADDRESS->appendChild($dom->createElement('NAME2'));
$NAME2->appendChild($dom->createTextNode($xml_SUPPLIER_NAME2));
$NAME3 = $ADDRESS->appendChild($dom->createElement('NAME3'));
$NAME3->appendChild($dom->createTextNode($xml_SUPPLIER_NAME3));
$STREET = $ADDRESS->appendChild($dom->createElement('STREET'));
$STREET->appendChild($dom->createTextNode($xml_SUPPLIER_STREET));
$ZIP = $ADDRESS->appendChild($dom->createElement('ZIP'));
$ZIP->appendChild($dom->createTextNode($xml_SUPPLIER_ZIP));
$CITY = $ADDRESS->appendChild($dom->createElement('CITY'));
$CITY->appendChild($dom->createTextNode($xml_SUPPLIER_CITY));
$COUNTRY = $ADDRESS->appendChild($dom->createElement('COUNTRY'));
$COUNTRY->appendChild($dom->createTextNode($xml_SUPPLIER_COUNTRY));
$FINAL_DELIVERY_PARTY = $SHIPMENT_PARTIES->appendChild($dom->createElement('FINAL_DELIVERY_PARTY'));
$PARTY = $FINAL_DELIVERY_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID = $PARTY->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID_ATT = $PARTY_ID->appendChild($dom->createAttribute('type'));
$PARTY_ID_ATT->value = 'buyer_specific';
$PARTY_ID->appendChild($dom->createTextNode(''));
$ADDRESS = $PARTY->appendChild($dom->createElement('ADDRESS'));
$NAME = $ADDRESS->appendChild($dom->createElement('NAME'));
$NAME->appendChild($dom->createTextNode($xml_BUYUR_NAME));
$NAME2 = $ADDRESS->appendChild($dom->createElement('NAME2'));
$NAME2->appendChild($dom->createTextNode($xml_BUYUR_NAME2));
$NAME3 = $ADDRESS->appendChild($dom->createElement('NAME3'));
$NAME3->appendChild($dom->createTextNode($xml_BUYUR_NAME3));
$STREET = $ADDRESS->appendChild($dom->createElement('STREET'));
$STREET->appendChild($dom->createTextNode($xml_BUYUR_STREET));
$ZIP = $ADDRESS->appendChild($dom->createElement('ZIP'));
$ZIP->appendChild($dom->createTextNode($xml_BUYUR_ZIP));
$CITY = $ADDRESS->appendChild($dom->createElement('CITY'));
$CITY->appendChild($dom->createTextNode($xml_BUYUR_CITY));
$COUNTRY = $ADDRESS->appendChild($dom->createElement('COUNTRY'));
$COUNTRY->appendChild($dom->createTextNode($xml_BUYUR_COUNTRY));
$PARTIAL_SHIPMENT_ALLOWED = $order_info->appendChild($order_info->appendChild($dom->createElement('PARTIAL_SHIPMENT_ALLOWED')));
$PARTIAL_SHIPMENT_ALLOWED->appendChild($dom->createTextNode('False'));
$TRANSPORT = $order_info->appendChild($order_info->appendChild($dom->createElement('TRANSPORT')));
$INCOTERM = $TRANSPORT->appendChild($dom->createElement('INCOTERM'));
$INCOTERM->appendChild($dom->createTextNode(''));
$LOCATION = $TRANSPORT->appendChild($dom->createElement('LOCATION'));
$LOCATION->appendChild($dom->createTextNode('EKD'));
$TRANSPORT_REMARK = $TRANSPORT->appendChild($dom->createElement('TRANSPORT_REMARK'));
$TRANSPORT_REMARK->appendChild($dom->createTextNode('10'));
$REMARK_GENERAL = $order_info->appendChild($order_info->appendChild($dom->createElement('REMARK')));
$REMARK_GENERAL_ = $REMARK_GENERAL->appendChild($dom->createAttribute('type'));
$REMARK_GENERAL_->value = 'general';
$REMARK_GENERAL->appendChild($dom->createTextNode('SUPERHANDIG.NL IS HÉT ADRES VOOR PROF. GEREEDSCHAP EN ACCESSOIRES!'));
$REMARK_ORDER = $order_info->appendChild($order_info->appendChild($dom->createElement('REMARK')));
$REMARK_ORDER_ = $REMARK_ORDER->appendChild($dom->createAttribute('type'));
$REMARK_ORDER_->value = 'order';
$REMARK_ORDER->appendChild($dom->createTextNode($voorletters.$xml_order_id));
$ORDER_ITEM_LIST = $root->appendChild($client = $dom->createElement('ORDER_ITEM_LIST'));
$i = 0;
foreach ($items as $item) {
$ean = get_post_meta($item['product_id'], '_sku'); // for single products
$qty = $item['qty'];
if(empty($ean[0])){
$ean = get_post_meta($item['variation_id'], '_sku'); // for variable products
}
$i++;
$ORDER_ITEM = $ORDER_ITEM_LIST->appendChild($dom->createElement('ORDER_ITEM'));
$LINE_ITEM_ID = $ORDER_ITEM->appendChild($dom->createElement('LINE_ITEM_ID'));
$LINE_ITEM_ID->appendChild($dom->createTextNode($i));
$ARTICLE_ID = $ORDER_ITEM->appendChild($dom->createElement('ARTICLE_ID'));
$SUPPLIER_AID = $ARTICLE_ID->appendChild($dom->createElement('SUPPLIER_AID'));
$SUPPLIER_AID->appendChild($dom->createTextNode(''));
$INTERNATIONAL_AID = $ARTICLE_ID->appendChild($dom->createElement('INTERNATIONAL_AID'));
$INTERNATIONAL_AID_ = $INTERNATIONAL_AID->appendChild($dom->createAttribute('type'));
$INTERNATIONAL_AID_->value = 'EAN';
$INTERNATIONAL_AID->appendChild($dom->createTextNode($ean[0]));
$BUYER_AID = $ARTICLE_ID->appendChild($dom->createElement('BUYER_AID'));
$BUYER_AID_ = $BUYER_AID->appendChild($dom->createAttribute('type'));
$BUYER_AID_->value = 'BP';
$BUYER_AID->appendChild($dom->createTextNode(''));
$BUYER_AID = $ARTICLE_ID->appendChild($dom->createElement('BUYER_AID'));
$BUYER_AID_ = $BUYER_AID->appendChild($dom->createAttribute('type'));
$BUYER_AID_->value = 'IN';
$BUYER_AID->appendChild($dom->createTextNode(''));
$DESCRIPTION_SHORT = $ARTICLE_ID->appendChild($dom->createElement('DESCRIPTION_SHORT'));
$DESCRIPTION_SHORT->appendChild($dom->createTextNode(''));
$QUANTITY = $ORDER_ITEM->appendChild($dom->createElement('QUANTITY'));
$QUANTITY->appendChild($dom->createTextNode($qty));
$ORDER_UNIT = $ORDER_ITEM->appendChild($dom->createElement('ORDER_UNIT'));
$ORDER_UNIT->appendChild($dom->createTextNode('C62'));
}
$ORDER_SUMMARY = $root->appendChild($client = $dom->createElement('ORDER_SUMMARY'));
$TOTAL_ITEM_NUM = $ORDER_SUMMARY->appendChild($dom->createElement('TOTAL_ITEM_NUM'));
$TOTAL_ITEM_NUM->appendChild($dom->createTextNode($i));
$dom->formatOutput = true;
$dom->save($_SERVER['DOCUMENT_ROOT'].'/ede_orders/xml/'.$voorletters.$xml_order_id.'.xml');
}
https://gist.github.com/webstylecenter/2491735366a70d82336512e0d0cc4e8f

Slow PHP Script YoutubeAPI

This script have very long loading times.
If i refresh my page it takes 3.5 seconds to load up this script.
What can causes this?
<?php
//Instagram Getter
// use this instagram access token generator http://instagram.pixelunion.net/
$access_token="";
$photo_count=9;
$json_instalink="https://api.instagram.com/v1/users/self/media/recent/?access_token=$access_token&count=$photo_count";
$jsoninsta = file_get_contents($json_instalink);
$objinsta = json_decode($jsoninsta);
//Link zu den Bildern
$imagelink1 = $objinsta->data[0]->link;
$imagelink2 = $objinsta->data[1]->link;
$imagelink3 = $objinsta->data[2]->link;
$imagelink4 = $objinsta->data[3]->link;
$imagelink5 = $objinsta->data[4]->link;
$imagelink6 = $objinsta->data[5]->link;
$imagelink7 = $objinsta->data[6]->link;
$imagelink8 = $objinsta->data[7]->link;
$imagelink9 = $objinsta->data[8]->link;
//Das Bild an sich
$profilelink1 = $objinsta->data[0]->images->standard_resolution->url;
$profilelink2 = $objinsta->data[1]->images->standard_resolution->url;
$profilelink3 = $objinsta->data[2]->images->standard_resolution->url;
$profilelink4 = $objinsta->data[3]->images->standard_resolution->url;
$profilelink5 = $objinsta->data[4]->images->standard_resolution->url;
$profilelink6 = $objinsta->data[5]->images->standard_resolution->url;
$profilelink7 = $objinsta->data[6]->images->standard_resolution->url;
$profilelink8 = $objinsta->data[7]->images->standard_resolution->url;
$profilelink9 = $objinsta->data[8]->images->standard_resolution->url;
//Channel and API Key
$channel_id = '';
$api_key = '';
//Channel Statistics
$json_statsurl="https://www.googleapis.com/youtube/v3/channels?part=statistics&id=$channel_id&key=$api_key";
$jsonstats = file_get_contents($json_statsurl);
$listFromYouTube=json_decode($jsonstats);
$subscriberCount = $listFromYouTube->items[0]->statistics->subscriberCount;
//Last Video
$json_lastvidurl="https://www.googleapis.com/youtube/v3/search?key=$api_key&channelId=$channel_id&part=id&order=date&maxResults=1";
$jsonlastvid = file_get_contents($json_lastvidurl);
$listFromYouTube=json_decode($jsonlastvid);
$lastvidid = $listFromYouTube->items[0]->id->videoId;
//Last Video Views
$json_lastvidstatsurl="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$lastvidid&key=$api_key";
$jsonlastvidstats = file_get_contents($json_lastvidstatsurl);
$listFromYouTube=json_decode($jsonlastvidstats);
$lastvidviews = $listFromYouTube->items[0]->statistics->viewCount;
//Last Video Published Date
$json_lastvidinfourl="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$lastvidid&key=$api_key";
$jsonlastvidinfo = file_get_contents($json_lastvidinfourl);
$listFromYouTube=json_decode($jsonlastvidinfo);
$lastvidtitle = $listFromYouTube->items[0]->snippet->title;
$lastvidpublished = $listFromYouTube->items[0]->snippet->publishedAt;
//Playlist Videos 9
$json_9vidurl="https://www.googleapis.com/youtube/v3/search?key=$api_key&channelId=$channel_id&part=snippet,id&order=date&maxResults=10";
$json9vid = file_get_contents($json_9vidurl);
$listFromYouTube=json_decode($json9vid);
$vid0=$listFromYouTube->items[1]->id->videoId;
$vid1=$listFromYouTube->items[2]->id->videoId;
$vid2=$listFromYouTube->items[3]->id->videoId;
$vid3=$listFromYouTube->items[4]->id->videoId;
$vid4=$listFromYouTube->items[5]->id->videoId;
$vid5=$listFromYouTube->items[6]->id->videoId;
$vid6=$listFromYouTube->items[7]->id->videoId;
$vid7=$listFromYouTube->items[8]->id->videoId;
$vid8=$listFromYouTube->items[9]->id->videoId;
$watchlink="http://undercover-gaming.de/youtube/video/";
// TITLE PART
$vid0t=$listFromYouTube->items[1]->snippet->title;
$vid1t=$listFromYouTube->items[2]->snippet->title;
$vid2t=$listFromYouTube->items[3]->snippet->title;
$vid3t=$listFromYouTube->items[4]->snippet->title;
$vid4t=$listFromYouTube->items[5]->snippet->title;
$vid5t=$listFromYouTube->items[6]->snippet->title;
$vid6t=$listFromYouTube->items[7]->snippet->title;
$vid7t=$listFromYouTube->items[8]->snippet->title;
$vid8t=$listFromYouTube->items[9]->snippet->title;
// PUBLISH PART
$json_vid0url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid0&key=$api_key";
$jsonlastvid0 = file_get_contents($json_vid0url);
$listFromYouTube=json_decode($jsonlastvid0);
$vid0published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid1url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid1&key=$api_key";
$jsonlastvid1 = file_get_contents($json_vid1url);
$listFromYouTube=json_decode($jsonlastvid1);
$vid1published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid2url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid2&key=$api_key";
$jsonlastvid2 = file_get_contents($json_vid2url);
$listFromYouTube=json_decode($jsonlastvid2);
$vid2published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid3url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid3&key=$api_key";
$jsonlastvid3 = file_get_contents($json_vid3url);
$listFromYouTube=json_decode($jsonlastvid3);
$vid3published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid4url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid4&key=$api_key";
$jsonlastvid4 = file_get_contents($json_vid4url);
$listFromYouTube=json_decode($jsonlastvid4);
$vid4published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid5url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid5&key=$api_key";
$jsonlastvid5 = file_get_contents($json_vid5url);
$listFromYouTube=json_decode($jsonlastvid5);
$vid5published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid6url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid6&key=$api_key";
$jsonlastvid6 = file_get_contents($json_vid6url);
$listFromYouTube=json_decode($jsonlastvid6);
$vid6published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid7url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid7&key=$api_key";
$jsonlastvid7 = file_get_contents($json_vid7url);
$listFromYouTube=json_decode($jsonlastvid7);
$vid7published = $listFromYouTube->items[0]->snippet->publishedAt;
$json_vid8url="https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$vid8&key=$api_key";
$jsonlastvid8 = file_get_contents($json_vid8url);
$listFromYouTube=json_decode($jsonlastvid8);
$vid8published = $listFromYouTube->items[0]->snippet->publishedAt;
//VIEW PART 0-8
$json_viewgetter="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid0&key=$api_key";
$jsonplaylistgetter = file_get_contents($json_viewgetter);
$listFromYouTube=json_decode($jsonplaylistgetter);
$vid0views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter1="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid1&key=$api_key";
$jsonplaylistgetter1 = file_get_contents($json_viewgetter1);
$listFromYouTube=json_decode($jsonplaylistgetter1);
$vid1views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter2="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid2&key=$api_key";
$jsonplaylistgetter2 = file_get_contents($json_viewgetter2);
$listFromYouTube=json_decode($jsonplaylistgetter2);
$vid2views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter3="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid3&key=$api_key";
$jsonplaylistgetter3 = file_get_contents($json_viewgetter3);
$listFromYouTube=json_decode($jsonplaylistgetter);
$vid3views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter4="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid4&key=$api_key";
$jsonplaylistgetter4 = file_get_contents($json_viewgetter4);
$listFromYouTube=json_decode($jsonplaylistgetter4);
$vid4views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter5="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid5&key=$api_key";
$jsonplaylistgetter5 = file_get_contents($json_viewgetter5);
$listFromYouTube=json_decode($jsonplaylistgetter5);
$vid5views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter6="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid6&key=$api_key";
$jsonplaylistgetter6 = file_get_contents($json_viewgetter6);
$listFromYouTube=json_decode($jsonplaylistgetter6);
$vid6views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter7="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid7&key=$api_key";
$jsonplaylistgetter7 = file_get_contents($json_viewgetter7);
$listFromYouTube=json_decode($jsonplaylistgetter7);
$vid7views=$listFromYouTube->items[0]->statistics->viewCount;
$json_viewgetter8="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$vid8&key=$api_key";
$jsonplaylistgetter8 = file_get_contents($json_viewgetter8);
$listFromYouTube=json_decode($jsonplaylistgetter8);
$vid8views=$listFromYouTube->items[0]->statistics->viewCount;
//Last Video Thumbnails
$images = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos/".$lastvidid."?v=2&alt=json"), true);
$images = $images['entry']['media$group']['media$thumbnail'];
$image = $images[count($images)-4]['url'];
$maxurl = "http://i.ytimg.com/vi/".$lastvidid."/maxresdefault.jpg";
$vidurl0 = "http://i.ytimg.com/vi/".$vid0."/maxresdefault.jpg";
$vidurl1 = "http://i.ytimg.com/vi/".$vid1."/maxresdefault.jpg";
$vidurl2 = "http://i.ytimg.com/vi/".$vid2."/maxresdefault.jpg";
$vidurl3 = "http://i.ytimg.com/vi/".$vid3."/maxresdefault.jpg";
$vidurl4 = "http://i.ytimg.com/vi/".$vid4."/maxresdefault.jpg";
$vidurl5 = "http://i.ytimg.com/vi/".$vid5."/maxresdefault.jpg";
$vidurl6 = "http://i.ytimg.com/vi/".$vid6."/maxresdefault.jpg";
$vidurl7 = "http://i.ytimg.com/vi/".$vid7."/maxresdefault.jpg";
$vidurl8 = "http://i.ytimg.com/vi/".$vid8."/maxresdefault.jpg";
$max = get_headers($maxurl);
if (substr($max[0], 9, 3) !== '404') {
$image = $maxurl;
}
?>
I changed my code a little bet and got not that much file_get_contents.
But i found out that the Instagram API is really slow. So if i integrate the
instagram API my page loaded really slow. If i use Jquery Code it works fast but, everyone can look into the code and see the script brackets and thats what i dont want.
<?php
//Instagram Getter
// use this instagram access token generator http://instagram.pixelunion.net/
$access_token="";
$photo_count=9;
$json_instalink="https://api.instagram.com/v1/users/self/media/recent/?access_token=$access_token&count=$photo_count";
$jsoninsta = file_get_contents($json_instalink);
$objinsta = json_decode($jsoninsta);
//Link zu den Bildern
$imagelink1 = $objinsta->data[0]->link;
$imagelink2 = $objinsta->data[1]->link;
$imagelink3 = $objinsta->data[2]->link;
$imagelink4 = $objinsta->data[3]->link;
$imagelink5 = $objinsta->data[4]->link;
$imagelink6 = $objinsta->data[5]->link;
$imagelink7 = $objinsta->data[6]->link;
$imagelink8 = $objinsta->data[7]->link;
$imagelink9 = $objinsta->data[8]->link;
//Das Bild an sich
$profilelink1 = $objinsta->data[0]->images->standard_resolution->url;
$profilelink2 = $objinsta->data[1]->images->standard_resolution->url;
$profilelink3 = $objinsta->data[2]->images->standard_resolution->url;
$profilelink4 = $objinsta->data[3]->images->standard_resolution->url;
$profilelink5 = $objinsta->data[4]->images->standard_resolution->url;
$profilelink6 = $objinsta->data[5]->images->standard_resolution->url;
$profilelink7 = $objinsta->data[6]->images->standard_resolution->url;
$profilelink8 = $objinsta->data[7]->images->standard_resolution->url;
$profilelink9 = $objinsta->data[8]->images->standard_resolution->url;
//Channel and API Key
$channel_id = '';
$api_key = '';
//Channel Statistics
$json_statsurl="https://www.googleapis.com/youtube/v3/channels?part=statistics&id=$channel_id&key=$api_key";
$jsonstats = file_get_contents($json_statsurl);
$listFromYouTube=json_decode($jsonstats);
$subscriberCount = $listFromYouTube->items[0]->statistics->subscriberCount;
//Last Video ID/Title/Published/Thumbnails
$json_lastvidurl="https://www.googleapis.com/youtube/v3/search?key=$api_key&channelId=$channel_id&part=snippet,id&order=date&maxResults=10";
$jsonlastvid = file_get_contents($json_lastvidurl);
$listFromYouTube=json_decode($jsonlastvid);
$lastvidid = $listFromYouTube->items[0]->id->videoId;
$lastvidtitle = $listFromYouTube->items[0]->snippet->title;
$lastvidpublished = $listFromYouTube->items[0]->snippet->publishedAt;
$maxurl = "http://i.ytimg.com/vi/".$lastvidid."/maxresdefault.jpg";
//Playlist Videos 9 ID/Title/Published/Thumbnails
$vid0=$listFromYouTube->items[1]->id->videoId;
$vid1=$listFromYouTube->items[2]->id->videoId;
$vid2=$listFromYouTube->items[3]->id->videoId;
$vid3=$listFromYouTube->items[4]->id->videoId;
$vid4=$listFromYouTube->items[5]->id->videoId;
$vid5=$listFromYouTube->items[6]->id->videoId;
$vid6=$listFromYouTube->items[7]->id->videoId;
$vid7=$listFromYouTube->items[8]->id->videoId;
$vid8=$listFromYouTube->items[9]->id->videoId;
$vid0t=$listFromYouTube->items[1]->snippet->title;
$vid1t=$listFromYouTube->items[2]->snippet->title;
$vid2t=$listFromYouTube->items[3]->snippet->title;
$vid3t=$listFromYouTube->items[4]->snippet->title;
$vid4t=$listFromYouTube->items[5]->snippet->title;
$vid5t=$listFromYouTube->items[6]->snippet->title;
$vid6t=$listFromYouTube->items[7]->snippet->title;
$vid7t=$listFromYouTube->items[8]->snippet->title;
$vid8t=$listFromYouTube->items[9]->snippet->title;
$vid0published = $listFromYouTube->items[1]->snippet->publishedAt;
$vid1published = $listFromYouTube->items[2]->snippet->publishedAt;
$vid2published = $listFromYouTube->items[3]->snippet->publishedAt;
$vid3published = $listFromYouTube->items[4]->snippet->publishedAt;
$vid4published = $listFromYouTube->items[5]->snippet->publishedAt;
$vid5published = $listFromYouTube->items[6]->snippet->publishedAt;
$vid6published = $listFromYouTube->items[7]->snippet->publishedAt;
$vid7published = $listFromYouTube->items[8]->snippet->publishedAt;
$vid8published = $listFromYouTube->items[9]->snippet->publishedAt;
$vidurl0 = "http://i.ytimg.com/vi/".$vid0."/maxresdefault.jpg";
$vidurl1 = "http://i.ytimg.com/vi/".$vid1."/maxresdefault.jpg";
$vidurl2 = "http://i.ytimg.com/vi/".$vid2."/maxresdefault.jpg";
$vidurl3 = "http://i.ytimg.com/vi/".$vid3."/maxresdefault.jpg";
$vidurl4 = "http://i.ytimg.com/vi/".$vid4."/maxresdefault.jpg";
$vidurl5 = "http://i.ytimg.com/vi/".$vid5."/maxresdefault.jpg";
$vidurl6 = "http://i.ytimg.com/vi/".$vid6."/maxresdefault.jpg";
$vidurl7 = "http://i.ytimg.com/vi/".$vid7."/maxresdefault.jpg";
$vidurl8 = "http://i.ytimg.com/vi/".$vid8."/maxresdefault.jpg";
//Last Video Views
$json_lastvidstatsurl="https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$lastvidid,$vid0,$vid1,$vid2,$vid3,$vid4,$vid5,$vid6,$vid7,$vid8&key=$api_key";
$jsonlastvidstats = file_get_contents($json_lastvidstatsurl);
$listFromYouTube=json_decode($jsonlastvidstats);
$lastvidviews = $listFromYouTube->items[0]->statistics->viewCount;
$vid0views = $listFromYouTube->items[1]->statistics->viewCount;
$vid1views = $listFromYouTube->items[2]->statistics->viewCount;
$vid2views = $listFromYouTube->items[3]->statistics->viewCount;
$vid3views = $listFromYouTube->items[4]->statistics->viewCount;
$vid4views = $listFromYouTube->items[5]->statistics->viewCount;
$vid5views = $listFromYouTube->items[6]->statistics->viewCount;
$vid6views = $listFromYouTube->items[7]->statistics->viewCount;
$vid7views = $listFromYouTube->items[8]->statistics->viewCount;
$vid8views = $listFromYouTube->items[9]->statistics->viewCount;
//Watchlink
$watchlink="http://undercover-gaming.de/youtube/video/";
?>

PHP module does not set quantity for prestashop

Hi I am using php module to add a new product. Everything works great but this code for some reason does not set the quantity of product.
$id_product = (int)Db::getInstance()->getValue("SELECT id_product FROM `$product` WHERE reference = '$product_xml[id]'");
$p = new Product();
$p->reference = $product_xml['id'];
$p->price = (float)$price;
$p->active = 1;
$p->quantity = (int)$product_xml['count'];
$p->minimal_quantity = 1;
$p->available_for_order=1;
$p->id_category = array(26);
$p->id_category_default = 26;
$p->name[1] = $product_xml['name'];
$p->description[1] = utf8_encode($product_xml->Description);
$p->description_short[1] = utf8_encode($product_xml->Short_Description);
$p->link_rewrite[1] = Tools::link_rewrite($product_xml['name']);
if (!isset($p->date_add) || empty($p->date_add))
$p->date_add = date('Y-m-d H:i:s');
$p->date_upd = date('Y-m-d H:i:s');
$p->save();
$id_product ? $p->updateCategories(array(26)) : $p->addToCategories(array(26));
You should also use:
StockAvailable::setQuantity($p->id, null, (int)$product_xml['count']);
Put that after your current code.

PHP-EWS 2010, how to set the IsRead flag

I have been able to successfully retrieve the unread emails from an Exchange 2010 inbox using php-ews API. However after I have fetched the emails, I want to set the IsRead property of the email to true, so that these messages do not appear the next time I fetch emails.
Anyone done this before ?
EDIT :
This is how I am trying to set the IsRead flag :
$message_id = ''; //id of message
$change_key = ''; //change key
$response = $ews->GetItem($request);
//print_r($response);exit;
if( $response->ResponseMessages->GetItemResponseMessage->ResponseCode == 'NoError' &&
$response->ResponseMessages->GetItemResponseMessage->ResponseClass == 'Success' ) {
$a = array();
$message = $response->ResponseMessages->GetItemResponseMessage->Items->Message;
$a['message_body'] = $message->Body->_;
$a['sender'] = $message->From->Mailbox->EmailAddress;
$a['subject'] = $message->ConversationTopic;
$data[] = $a;
//process the message data.
$messageType = new EWSType_MessageType();
$messageType->IsRead = true;
$path = new EWSType_PathToUnindexedFieldType();
$path->FieldURI = 'message:IsRead';
$setField = new EWSType_SetItemFieldType();
$setField->Message = $messageType;
$setField->FieldURI = $path;
$u = new EWSType_ItemChangeType();
$u->Updates = new EWSType_NonEmptyArrayOfItemChangeDescriptionsType();
$u->Updates->SetItemField = $setField;
$u->ItemId = new EWSType_ItemIdType();
$u->ItemId->Id = $message_id;
$u->ItemId->ChangeKey = $change_key;
$updatedItems = new EWSType_NonEmptyArrayOfItemChangesType();
$updatedItems->ItemChange = $u;
$updateMessenger = new EWSType_UpdateItemType();
$updateMessenger->ItemChanges = $updatedItems;
$updateMessenger->MessageDisposition = 'SaveOnly';
$updateMessenger->ConflictResolution = 'AutoResolve';
try {
$update_response = $ews->UpdateItem($updateMessenger);
}catch (Exception $e){
echo $e->getMessage();
}
}
When I run the file I get the following error :
An internal server error occurred. The operation failed.
After debugging for some time, I have concluded that the error happens at the curl_exec function in NTLMSoapClient.php file.
I dont know where to go on from here. Please help.
I've faced a similar issue when updating a calendar event and setting the IsAllDayEvent flag. This is the code that worked for me:
$ews = new ExchangeWebServices(...);
$request = new EWSType_UpdateItemType();
$request->ConflictResolution = 'AlwaysOverwrite';
$request->ItemChanges = array();
$change = new EWSType_ItemChangeType();
$change->ItemId = new EWSType_ItemIdType();
$change->ItemId->Id = $id;
$change->ItemId->ChangeKey = $changeKey;
$field = new EWSType_SetItemFieldType();
$field->FieldURI = new EWSType_PathToUnindexedFieldType();
$field->FieldURI->FieldURI = "calendar:IsAllDayEvent";
$field->CalendarItem = new EWSType_CalendarItemType();
$field->CalendarItem->IsAllDayEvent = true;
$change->Updates->SetItemField[] = $field;
$request->ItemChanges[] = $change;
$response = $ews->UpdateItem($request);
The biggest difference I see here is that you do $u->Updates->SetItemField = $setField;, whereas my code uses $u->Updates->SetItemField[] = $setField;.
I hope this helps.
Edit: You might have already seen this, but I based my code on the one from the php-ews wiki.
I tried everything including PathToExtendedFieldType and it doesn't work at the end code below worked for me
$ews = new ExchangeWebServices('red', 'red', 'red',ExchangeWebServices::VERSION_2007_SP1);
$request = new EWSType_UpdateItemType();
$request->SendMeetingInvitationsOrCancellations = 'SendToNone';
$request->MessageDisposition = 'SaveOnly';
$request->ConflictResolution = 'AlwaysOverwrite';
$request->ItemChanges = array();
// Build out item change request.
$change = new EWSType_ItemChangeType();
$change->ItemId = new EWSType_ItemIdType();
$change->ItemId->Id = $contact_id;
$change->ItemId->ChangeKey = $contact_change_key;
#$change->Updates = new EWSType_NonEmptyArrayOfItemChangeDescriptionsType();
#$change->Updates->SetItemField = array();
// Build the set item field object and set the item on it.
$field = new EWSType_SetItemFieldType();
$field->FieldURI = new EWSType_PathToUnindexedFieldType();
$field->FieldURI->FieldURI = "message:IsRead";
$field->Message = new EWSType_MessageType();
$field->Message->IsRead = true;
$change->Updates->SetItemField[] = $field;
$request->ItemChanges[] = $change;
$response = $ews->UpdateItem($request);
var_dump($response);
Well, i dont know how it is in php, but in C# there is another field, that must be set: IsReadSpecified = true.
email.IsRead = true;
email.IsReadSpecified = true;

Categories