/**
  * send the request to the API nad return the result as an array
  * @param  String $action the query to action
  * @return  String
  */
 protected function request($action)
 {
     try {
         $response = $this->client->request('GET', self::buildURI($action), $this->headers);
         return json_decode($response->getBody()->getContents());
     } catch (RequestException $e) {
         logErrors($e->getMessage());
     }
 }
 /**
  * get all the films 
  * @return Array - VeeziAPI\Repositories\Film\FilmListing
  */
 public function films()
 {
     $films = [];
     try {
         $all_films = parent::request('film');
         foreach ($all_films as $index => $film) {
             $films[] = new FilmListing($film);
         }
         return $films;
     } catch (Exception $e) {
         logErrors($e->getMessage());
     }
 }
Esempio n. 3
0
function fatalErrorShutdownHandler()
{
    $last_error = error_get_last();
    if ($last_error['type'] === E_ERROR || $last_error['type'] === E_PARSE) {
        global $_handled_errors;
        // fatal error
        error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
        if (!empty($_handled_errors)) {
            @ob_clean();
            echo json_encode($_handled_errors);
            logErrors(new \ErrorException($last_error['message'], 0, 1, $last_error['file'], $last_error['line']), 500);
        }
        header("HTTP/1.0 500 Service not available");
    }
}
 public static function outputException(Exception $e, $app, $standardOutput = true)
 {
     $debug = $app->config('debug');
     $err = self::prepareError($e);
     // set http code
     $app->response->setStatus(self::getStatusCode($e->getCode()));
     $app->result = $err;
     // Logging error full info to error file
     $status = $app->response->status();
     logErrors($e, $status);
     // print error
     if ($standardOutput && isset($app->printResult)) {
         if ($debug) {
             $app->config('debug', false);
         }
         $app->printResult;
         if ($debug) {
             $app->config('debug', $debug);
         }
     } else {
         $app->response->headers->set('Content-Type', 'application/json');
         echo json_encode($app->result);
     }
 }
		try {
			$resultArray = array($fields['username'],$fields['firstname'],$fields['lastname'],booleanToString($fields['isadmin']),$fields['created'],$fields['lastlogin']);
			foreach ($teamsArray as $key=>$value) {
				// logErrors("team id: ".$key);
				if($team = Team::lookup(intval($key)))
				{
					logErrors(json_encode($team->getName()));
					array_push($resultArray,booleanToString($team->hasMember(Staff::lookup(intval($fields['staff_id'])))));	
				}
			}
			// logErrors(json_encode($resultArray));
			fputcsv($fp,$resultArray);
	    // fputcsv($fp, array_merge(array($fields['username'],$fields['firstname'],$fields['lastname'],$fields['isadmin'],$fields['onvacation'],$fields['created'],$fields['lastlogin']),null));
		
		} catch (Exception $e) {
			logErrors('Caught exception: ',  $e->getMessage(), "\n");
		}
	}

}

fclose($fp);

// ini_set('auto_detect_line_endings',TRUE);
echo "\xEF\xBB\xBF"; 
// header("Cache-Control: no-store, no-cache, must-revalidate"); 
// header("Cache-Control: post-check=0, pre-check=0", false); 
// header("Cache-Control: private",false); 
// header("Pragma: no-cache");
// header('Content-Length: ' . filesize($filePath));
header('Content-Type: text/csv;charset=utf-8');
Esempio n. 6
0
function createTicketByWebService($xml)
{
    global $logFilePath;
    try {
        if (!empty($xml)) {
            $nodes = $xml->xpath('/contacts/contact');
        } else {
            logErrors("The xml file can not be loaded ");
        }
        for ($i = 0; $i < count($nodes); $i++) {
            // echo json_encode($nodes[$i]);
            $data = array();
            // $data['recipients'] = array();
            $data['subject'] = removeLineBreaker($nodes[$i]->title);
            if (empty(removeLineBreaker($nodes[$i]->title))) {
                if (!empty(removeLineBreaker($nodes[$i]->crmsubject2_text))) {
                    $data['subject'] = removeLineBreaker($nodes[$i]->crmsubject2_text);
                } else {
                    $data['subject'] = "no title";
                }
            }
            $data['header'] = "";
            // $data['mid'] = 1;
            $data['source'] = "Web";
            $data['topicId'] = 2;
            $data['priorityId'] = 2;
            $data['crm_contact_id'] = $nodes[$i]->attributes()->id;
            // $data['flags'] = new ArrayObject();
            $data['email'] = trim(removeLineBreaker($nodes[$i]->email));
            if (empty($data['email'])) {
                $data['email'] = "*****@*****.**";
            }
            $data['phone'] = removeLineBreaker($nodes[$i]->phone);
            if (empty($data['phone'])) {
                $data['phone'] = "";
            }
            $data['name'] = trim(removeLineBreaker($nodes[$i]->name));
            if (empty($data['name'])) {
                $data['name'] = "Anonymous User";
            }
            $data['orderNumber'] = trim(removeLineBreaker($nodes[$i]->ordernumber));
            $data['ordernumber'] = trim(removeLineBreaker($nodes[$i]->ordernumber));
            $data['filenumber'] = trim(removeLineBreaker($nodes[$i]->filenumber));
            $data['cvr'] = trim(removeLineBreaker($nodes[$i]->cvr));
            $data['CVR'] = trim(removeLineBreaker($nodes[$i]->cvr));
            $data['message'] = removeLineBreaker($nodes[$i]->content);
            $data['companyName'] = removeLineBreaker($nodes[$i]->companyname);
            $data['company'] = removeLineBreaker($nodes[$i]->companyname);
            $data['business_form_id'] = removeLineBreaker($nodes[$i]->business_form_id);
            $data['activityCode'] = removeLineBreaker($nodes[$i]->activitycode);
            $data['activityDescription'] = removeLineBreaker($nodes[$i]->activitydescription);
            $data['useragent'] = removeLineBreaker($nodes[$i]->useragent);
            $crmsubject1_id = trim(removeLineBreaker($nodes[$i]->crmsubject_id));
            if (is_numeric($crmsubject1_id)) {
                $data['CRM_filter_subject1'] = removeLineBreaker($nodes[$i]->crmsubject_text);
                $data['crmsubject1_id'] = intval($crmsubject1_id);
                $data['crmsubject1_text'] = removeLineBreaker($nodes[$i]->crmsubject_text);
            } else {
                die("crmsubject1_id is not numeric");
            }
            $crmsubject2_id = trim(removeLineBreaker($nodes[$i]->crmsubject2_id));
            if (is_numeric($crmsubject2_id)) {
                $data['CRM_filter_subject2'] = removeLineBreaker($nodes[$i]->crmsubject2_text);
                $data['crmsubject2_id'] = intval($crmsubject2_id);
                $data['crmsubject2_text'] = removeLineBreaker($nodes[$i]->crmsubject2_text);
            } else {
                die("crmsubject2_id is not numeric");
            }
            // $data['flags']['bounce'] = true;
            $user = null;
            $acct = null;
            if (!$user && $data['email']) {
                $user = User::lookupByEmail($data['email']);
            }
            if (!$user) {
                $user_form = UserForm::getUserForm()->getForm($data);
                if (!($user = User::fromVars($user_form->getClean()))) {
                    echo 'Unable to register account.';
                }
                if (!($acct = ClientAccount::createForUser($user))) {
                    echo 'Internal error. Unable to create new account';
                }
            }
            $fileContent = $nodes[$i]->files->file;
            $data['fileContent'] = $fileContent;
            $tform = TicketForm::objects()->one()->getForm();
            $messageField = $tform->getField('message');
            $fileField = $messageField->getWidget()->getAttachments();
            for ($j = 0; $j < count($fileContent); $j++) {
                $fileId = $fileContent[$j]->attributes()->id;
                $file['name'] = $fileContent[$j]->name;
                $file['type'] = $fileContent[$j]->mime;
                $file['encoding'] = 'base64';
                // $file['cid'] = false;
                $url = "https://w2l.dk" . $fileContent[$j]->url;
                // logErrors("A test");
                // $url = $fileContent[$j]->url;
                // $file['data'] = base64_encode(file_get_contents($url));
                if ($file['data'] = getFileContentsSSL($url)) {
                    $timestamp = date("Y-m-d_H:i:s");
                    // if(!file_put_contents(CLIENTINC_DIR.'erstFile/'.$timestamp.$file['name'], $file['data']))
                    //     logErrors("not able to store the file");
                    try {
                        $storeCRMFile = "/var/www/html/erstFile/" . $timestamp . $file['name'];
                        echo $storeCRMFile;
                        file_put_contents("/var/www/html/erstFile/" . $timestamp . $file['name'], $file['data']);
                    } catch (Exception $e) {
                        logErrors('Caught exception: ', $e->getMessage(), "\n");
                    }
                } else {
                    logErrors("The file url is not valid");
                }
                // try {
                //     $file['id'] = $fileField->uploadAttachment($file);
                // }
                // catch (FileUploadError $ex) {
                //     $file['error'] = $file['name'] . ': ' . $ex->getMessage();
                //     echo $file['error'];
                // }
                $data['attachments'][] = $file;
                // echo $file['data'];
                // echo "<br/>";
            }
            // echo "22222";
            // echo json_encode($data);
            if (Ticket::lookupForContactId($data['crm_contact_id'])) {
                $api = new TicketApiController();
                $api->createTicket($data);
                echo "ticket has been generated successfully <br/>";
                if (DELETE_ERST_SERVICE_QUEUE) {
                    deleteContactsFromQueue($data['crm_contact_id']);
                } else {
                    logErrors("please go to include/ost-config to make the DELETE_ERST_SERVICE_QUEUE to true");
                }
            } else {
                logErrors("ticket with id " . $data['crm_contact_id'] . " has already exists");
            }
        }
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }
}
Esempio n. 7
0
 function pdfExport($psize = 'Letter', $notes = false, $printAttachments)
 {
     global $thisstaff;
     require_once INCLUDE_DIR . 'class.pdf.php';
     if (!is_string($psize)) {
         if ($_SESSION['PAPER_SIZE']) {
             $psize = $_SESSION['PAPER_SIZE'];
         } elseif (!$thisstaff || !($psize = $thisstaff->getDefaultPaperSize())) {
             $psize = 'Letter';
         }
     }
     $pdfConverterPath = INCLUDE_DIR . 'pdfConverter/';
     $cmd = " find " . $pdfConverterPath . ' -type f -delete';
     shell_exec($cmd);
     $name = 'Ticket.pdf';
     $pdf = new Ticket2PDF($this, $psize, $notes);
     $pdf->Output($pdfConverterPath . $name, 'F');
     $cmd = "chmod -R 777 " . $pdfConverterPath . $name;
     shell_exec($cmd);
     $pdf = new mPDF('c');
     $pdf->allow_charset_conversion = true;
     // Set by default to TRUE
     $pdf->charset_in = 'windows-1252';
     $pdf->SetImportUse();
     $this->importPdfPages($pdf, $pdfConverterPath . $name);
     $attachmentOrder = 1;
     foreach ($printAttachments as $attachmentId) {
         if (!($f = AttachmentFile::lookup(intval($attachmentId)))) {
             break;
         }
         // $this->logErrors($f->getDownloadUrl());
         // $this->logErrors("http://mailtest.spitzeco.dk/".$f->getDownloadUrl());
         if ($fileData = $f->getData()) {
             // $this->logErrors(json_encode($file['data']));
             $timestamp = date("Y-m-d_H");
             $extension = pathinfo($f->getName(), PATHINFO_EXTENSION);
             // $this->logErrors("fileName  ".$f->getName());
             $stringName = preg_replace('/\\s+/', '', $f->getName());
             // $tempName = $timestamp.basename($stringName, '.'.$extension);
             // give the file a temp name in case the file name contians some blank space and then the command would take effect
             $tempName = "tempFile" . $attachmentOrder;
             file_put_contents($pdfConverterPath . $tempName . "." . $extension, $fileData);
             $originalFileName = $pdfConverterPath . $tempName . "." . $extension;
             $formattedFile = $tempName . "formatted.pdf";
             $cmd = "chmod -R 777 " . $pdfConverterPath . $tempName . "." . $extension;
             shell_exec($cmd);
             // this is a command for changing other format to pdf
             $cmd = 'export HOME=/tmp && /usr/bin/libreoffice5.0 --headless --convert-to pdf --outdir ' . $pdfConverterPath . " " . $pdfConverterPath . $tempName . "." . $extension;
             // $this->logErrors("2222222 ".$cmd);
             system($cmd);
             $cmd = "chmod -R 777 " . $pdfConverterPath . $tempName . ".pdf";
             shell_exec($cmd);
             // this command is for making unformatted files become formatted
             $cmd = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=' . $pdfConverterPath . $formattedFile . ' ' . $pdfConverterPath . $tempName . ".pdf";
             shell_exec($cmd);
             $cmd = "chmod -R 777 " . $pdfConverterPath . $formattedFile;
             shell_exec($cmd);
             try {
                 $this->importPdfPages($pdf, $pdfConverterPath . $formattedFile);
                 $cmd = "chmod -R 777 " . $pdfConverterPath . $tempName . ".pdf";
                 shell_exec($cmd);
             } catch (Exception $e) {
                 logErrors('Caught exception: ', $e->getMessage(), "\n");
                 break;
             }
             $attachmentOrder = $attachmentOrder + 1;
         }
     }
     $name = 'Ticket-' . $this->getNumber() . '.pdf';
     $pdf->Output($name, 'I');
     //Remember what the user selected - for autoselect on the next print.
     $_SESSION['PAPER_SIZE'] = $psize;
     exit;
 }