DIsplay all otrs ticket using soap api - php

How can i display all the otrs tickets using a soap api. Individual ticket can be displayed by passing ticket id in url like this:
$url = "https://url/otrs/rpc.pl"; //// URL for OTRS server
$username = "username"; //// SOAP username set in sysconfig
$password = "password"; //// SOAP password set in sysconfig
$TicketID = $_GET['id'];
//////// Initialize new client session ////////
$client = new SoapClient(
null,
array(
'location' => $url,
'uri' => "Core",
'trace' => 1,
'login' => $username,
'password' => $password,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED
)
);
//////// Create and send the SOAP Function Call ////////
$sql =
$TicketDetails = $client->__soapCall("Dispatch",
array($username, $password,
"TicketObject", "TicketGet",
"TicketID", $TicketID,
));
$ticketInfo = array();
$i = 0;
foreach ($TicketDetails as $name => $value){ //// explode the xml response
if (false !== strpos($name, "s-gensym")){
$temp[$i] = $value;
$v = $temp[$i - 1];
if($i % 2 != 0){
$ticketInfo[$v] = $value;
}
$i++;
}
}
var_dump($ticketInfo);
exit();
How can i display all the tickets using api?????

Use the TicketSearch API call in order to retrieve a list of Ticket IDs. Then feed this list to TicketGet as you already showed in order to retrieve ticket details.

Related

How to post an event directly to another user's calendar

i want To post an event directly to another user's calendar with jamesiarmes/php-ews but in example i have find only how to make it with invitation.
I have admin account so i can write in athers user's post calendar directly.
i don't understant a lot because i'm new in ews so thx for any help.
// Replace this with your desired start/end times and guests.
$start = new DateTime('tomorrow 4:00pm');
$end = new DateTime('tomorrow 5:00pm');
$guests = array(
array(
'name' => 'Homer Simpson',
'email' => 'hsimpson#example.com',
),
array(
'name' => 'Marge Simpson',
'email' => 'msimpson#example.com',
),
);
// Set connection information.
$host = '';
$username = '';
$password = '';
$version = Client::VERSION_2016;
$client = new Client($host, $username, $password, $version);
// Build the request,
$request = new CreateItemType();
$request->SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items = new NonEmptyArrayOfAllItemsType();
// Build the event to be added.
$event = new CalendarItemType();
$event->RequiredAttendees = new NonEmptyArrayOfAttendeesType();
$event->Start = $start->format('c');
$event->End = $end->format('c');
$event->Subject = 'EWS Test Event';
// Set the event body.
$event->Body = new BodyType();
$event->Body->_ = 'This is the event body';
$event->Body->BodyType = BodyTypeType::TEXT;
// Iterate over the guests, adding each as an attendee to the request.
foreach ($guests as $guest) {
$attendee = new AttendeeType();
$attendee->Mailbox = new EmailAddressType();
$attendee->Mailbox->EmailAddress = $guest['email'];
$attendee->Mailbox->Name = $guest['name'];
$attendee->Mailbox->RoutingType = RoutingType::SMTP;
$event->RequiredAttendees->Attendee[] = $attendee;
}
// Add the event to the request. You could add multiple events to create more
// than one in a single request.
$request->Items->CalendarItem[] = $event;
$response = $client->CreateItem($request);
// Iterate over the results, printing any error messages or event ids.
$response_messages = $response->ResponseMessages->CreateItemResponseMessage;
foreach ($response_messages as $response_message) {
// Make sure the request succeeded.
if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
$code = $response_message->ResponseCode;
$message = $response_message->MessageText;
fwrite(STDERR, "Event failed to create with \"$code: $message\"\n");
continue;
}
// Iterate over the created events, printing the id for each.
foreach ($response_message->Items->CalendarItem as $item) {
$id = $item->ItemId->Id;
fwrite(STDOUT, "Created event $id\n");
}
}
You define the attendees but miss the account where you want to create the event in:add this code before the $response
...
$request->Items->CalendarItem[] = $event;
//following lines are missing
$lsEmail = 'some#email.de';
$request->SavedItemFolderId = new TargetFolderIdType();
$request->SavedItemFolderId->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->SavedItemFolderId->DistinguishedFolderId->Id = self::DISTINGUISHED_FOLDER_ID;
$request->SavedItemFolderId->DistinguishedFolderId->Mailbox = new EmailAddressType();
$request->SavedItemFolderId->DistinguishedFolderId->Mailbox->EmailAddress = $lsEmail;
// here your code continues
$response = $client->CreateItem($request);
...

Square API - invalid character 'C' looking for beginning of value

I am using Square Charge API, and following is my request object for a test card -
I am using Square provided PHP client to connect to the API. And I am receiving following response for "Charge" endpoint -
[HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"BAD_REQUEST","detail":"invalid character 'C' looking for beginning of value (line 1, character 1)"}]}
Following is my code in PHP -
public function chargeCustomerCard($userId, $custId, $cardId, $note, $billingAddres, $amount, $idempotencyKey){
$billingAddrRequest = array("address_line_1" => $billingAddres->addr1, "address_line_2" => $billingAddres->addr2, "locality" => $billingAddres->city, "administrative_district_level_1" => $billingAddres->state, "postal_code" => $billingAddres->zip, "country" => $billingAddres->country);
$billingAddressReq = new \SquareConnect\Model\Address($billingAddrRequest);
$moneyRequest = array("amount" => $amount, "currency" => "USD");
$money = new \SquareConnect\Model\Money($moneyRequest);
$request = array("idempotency_key" => $idempotencyKey, "customer_id" => $custId, "customer_card_id" => $cardId, "delay_capture" => false, "amount_money" => $money, "billing_address" => $billingAddressReq, "note" => $note, "reference_id" => $userId);
$charge = new \SquareConnect\Model\ChargeRequest($request);
$response = null;
try{
$charge_api = new \SquareConnect\Api\TransactionsApi();
$response = $charge_api->charge($this->authtoken, $this->locationId, $charge);
if($response != null && count($response->getErrors()) == 0){
$transaction = $response->getTransaction();
$data = array();
$data['transactionId'] = $transaction->getId();
$data['created'] = $transaction->getCreatedAt();
$data['referenceId'] = $transaction->getReferenceId(); //this should be equal to userid
$tender = $transaction->getTenders()[0];
$data['tenderId'] = $tender->getId();
$data['note'] = $tender->getNote();
$data['amount'] = ($tender->getAmountMoney()->getAmount())/100;
$data['currency'] = $tender->getAmountMoney()->getCurrency();
$processingFee = $tender->getProcessingFeeMoney();
if(isset($processingFee) && !empty($processingFee)){
$data['processingFee'] = $tender->getProcessingFeeMoney()->getAmount();
}else{
$data['processingFee'] = 0;
}
$data['tendertype'] = $tender->getType();
$data['cardStatus'] = $tender->getCardDetails()->getStatus();
$data['cardBrand'] = $tender->getCardDetails()->getCard()->getCardBrand();
$data['cardLast4'] = $tender->getCardDetails()->getCard()->getLast4();
$data['idempotencyKey'] = $idempotencyKey;
$data['customerPayId'] = $custId;
$data['customerCardId'] = $cardId;
return $this->generateReturnData(PAY_API_SUCCESS, '', $data);
}else{
return $this->generateReturnData(PAY_API_FAIL, '', $response->getErrors());
}
}catch(Exception $e) {
return $e->getMessage();
}
}
Can someone please point out to me what am I doing wrong here. I am really stuck here. Other API endpoints are working fine, such as, Create Customer, Create Customer Card API endpoints, using the same approach and same PHP client provided by square.
PS - this is on sandbox

I am not able to add members in a cohort externally in moodle

I am trying to add members in a cohort but whenever i call the function this is the response i get.I am using drupal rest to make the api call.
{
"exception": "dml_write_exception",
"errorcode": "dmlwriteexception",
"message": "Error writing to database",
"debuginfo": "Column 'role_id' cannot be null\nINSERT INTO mdl_cohort_members (cohortid,userid,timeadded,role_id) VALUES(?,?,?,?)\n[array (\n 0 => '3',\n 1 => '52367',\n 2 => 1460546128,\n 3 => NULL,\n)]"
}
Can somebody direct me towards the solution.
{
$fname = 'core_cohort_add_cohort_members';
/// Paramètres
$member = new stdClass();
$member->cohorttype['type']='id';
$member->cohorttype['value']='3';
$member->usertype['type']='id';
$member->usertype['value']='5';
$members = array($member);
$par = array('members' => $members);
$rest_format = 'json';
$Serve_Url = 'http://dev-lms.teletaleem.net' . '/webservice/rest/server.php'. '?wstoken=' . '7882bb500bcefcd8778de64b8e79a19a' .'&wsfunction='. $fname;
require_once('curl.inc');
$Rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$rep = $curl->post($Serve_Url.$Rest_format, $par);
dpm($rep);
}

Rename mongo database

I am doing project using mongodb and php. so here I tried to rename existing database using php. so I did following way to rename database.
first I create new database( user new database name)
read all records from old db and insert to new db
then I drop old db
this is my code.
$conn = new \MongoClient('mongodb://example.com:27017', array("connect" => TRUE));
$exist_dbs = $conn->listDBs();
foreach ($exist_dbs["databases"] as $databse) {
if ($databse['name'] == $new_name) {
$new_name_is_exist = true;
}
}
if (!$new_name_is_exist) {
$db = new \MongoDB($conn, $old_name);
//create new database
$db_new = new \MongoDB($conn, $new_name);
$collections = $db->getCollectionNames();
foreach ($collections as $collection) {
//create collection
$new_collection = new \MongoCollection($db_new, $collection);
$mongo_collection = $db->$collection;
$objects = $mongo_collection->find();
while ($document = $objects->getNext()) {
//add records
$new_collection->insert($document);
}
}
$db->drop();
$msg = 'database renamed';
} else {
$msg = 'given database name already exist';
}
$conn->close();
it works fine. but I would like to know is there any better way to rename mongo database using php?
Copy db (php + mongodb):
<?php
$rename = 'oldname';
$name = 'newname';
$mongo = (new MongoClient());
$db = $mongo->admin;
$response = $db->command(array(
'copydb' => 1,
'fromhost' => 'localhost',
'fromdb' => $rename,
'todb' => $name
));
print_r($response);
Drop db (php + mongodb):
<?php
$name = 'oldname';
$mongo = (new MongoClient());
$db = $mongo->$name;
$response = $db->command(array(
'dropDatabase' => 1
));
print_r($response);
$db=new new Mongo();
Copy old_db to new_db
$responseCopy = $db->admin->command(array(
'copydb' => 1,
'fromhost' => 'localhost',
'fromdb' => 'old_db',
'todb' =>'new_db'
));
Now drop old_db
if($responseCopy['ok']==1){
$responseDrop=$db->old_db->command(array('dropDatabase' => 1));
//OR
$responseDrop =$db->old_db->drop();
}
Show Output
print_r($responseCopy);
print_r($responseDrop);
Output will be something like this
Array ( [ok] => 1 )
Array ( [dropped] => old_db [ok] => 1 )
you can use this
$mongo = new MongoClient('_MONGODB_HOST_URL_');
$query = array("renameCollection" => "Database.OldName", "to" => "Database.NewName", "dropTarget" => "true");
$mongo->admin->command($query);

Assigning gid to new user in joomla 1.5

I've created several new child groups under registered users and when I create a new user from the backend, everything works fine. When trying to create an account on the frontend the system is giving them the gid of the parent group (registered users). I would like to know if you can pass the gid to joomla. Here's the script I'm using that's not working. Many thanks!
// Begin create user
global $mainframe;
JFactory::getLanguage()->load('com_user');
$this->execPieceByName('ff_InitLib');
$user = clone(JFactory::getUser());
$pathway =& $mainframe->getPathway();
$config =& JFactory::getConfig();
$authorize =& JFactory::getACL();
$document =& JFactory::getDocument();
// If user registration is not allowed, show 403 not authorized.
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
echo '<script>alert("Access forbidden");history.go(-1);</script>';
return;
} else {
// Initialize new usertype setting
$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype) {
$newUsertype = 'Free User';
}
// Bind the post array to the user object
$post = array(
'name' => ff_getSubmit('ownerName'),
'username' => ff_getSubmit('ownerEmail'),
'email' => ff_getSubmit('ownerEmail'),
'password' => ff_getSubmit('password'),
'password2' => ff_getSubmit('password'),
'task' => 'register_save',
'id' => '0',
'gid' => ff_getSubmit('101'),
);
if (!$user->bind( $post, 'usertype' )) {
echo '<script>alert("'.addslashes($user- >getError()).'");history.go(-1);</script>';
return;
} else {
// Set some initial user values
$user->set('id', 0);
$user->set('usertype', 'Free User');
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
// If there was an error with registration, set the message and display form
if ( !$user->save() )
{
echo '<script>alert("'.addslashes(JText::_( $user->getError())).'");history.go(-1);</script>';
return;
} else {
$db =& JFactory::getDBO();
$name = $user->get('name');
$email = $user->get('email');
$username = $user->get('username');
JFactory::getDBO()->setQuery("Update #__facileforms_records Set user_id = '".$user->get('id')."',
username = ".JFactory::getDBO()->Quote($username).", user_full_name = ".JFactory::getDBO()->Quote($name)." Where id = '".$this->record_id."'");
JFactory::getDBO()->query();
}
}
}
[SOLVED] Assigning gid to new user in joomla 1.5
I figured it out. If anyone else looking for an answer to this questions, just replace this line of code:
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
with
$user->set('gid', 'your gid#);

Categories