Search
Search
Search
Search
Information
Information
Light
Dark
Open actions menu
Basic upload method
Bypass upload method
Tips!
If you encounter an error (by firewall) while uploading using both methods,
try changing extension of the file before uploading it and rename it right after.
This uploader supports multiple file upload.
Submit
~
var
www
penneotest.bitkit.dk
httpdocs
app
Http
Controllers
File Content:
PodioController.php
<?php namespace App\Http\Controllers; use App\Http\Helpers\PodioHelper; use App\Modules\PodioConfig; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Podio; use PodioError; use PodioHook; use PodioItem; class PodioController extends Controller { use PodioHelper; /** * Handle hook from Contract app * @param Request $request */ public function signatureAppHook(Request $request) { $app_name = PodioConfig::$app_name_contract; $podioApp = new PodioController(); $podioApp->podioSetup(); $authenticate = $podioApp->podioAppAuthentication($app_name); if ($authenticate) { if ($request) { switch ($request->get("type")) { case 'hook.verify': if ($request->get("code") && $request->get("hook_id")) PodioHook::validate($request->get("hook_id"), array('code' => $request->get("code"))); break; case 'item.update': $this->statusChange(intval($request->get("item_id")), intval($request->get("item_revision_id"))); break; } } } } /** * Setup Podio ClientId & Client Secret */ public function podioSetup() { try { PodioConfig::initialise(); Podio::setup(PodioConfig::$clientId, PodioConfig::$clientSecret); } catch (PodioError $podioError) { Log::info(" PodioError : Podio Setup Error :- PodioController ( podioSetup )"); } } /** * Authenticating With App * @param $app - Name of the App to Authenticate * @return bool */ public function podioAppAuthentication($app) { try { PodioConfig::setupApp($app); Podio::authenticate_with_app(PodioConfig::$appId, PodioConfig::$appToken); return TRUE; } catch (PodioError $podioError) { Log::info(" PodioError : Podio App Authentication Error :- PodioController ( podioAuthentication )"); return FALSE; } } /** * Function When Status Change * @param $contract_item_id * @param $revision_id */ public function statusChange($contract_item_id, $revision_id) { if ($contract_item_id == 635845687) { Log::info('hai'); $penneoApp = new PenneoController(); list($check_status, $contract_item_details) = $this->checkUpdateIsForPenneo($contract_item_id, $revision_id); if ($check_status) { // checking whether the change is for Penneo actions if ($contract_item_details['contract_status_id'] == 3) { // cancel penneo signature process $penneoCaseFileFieldId = PodioConfig::$podio_field_id['CONTRACT']['PENNEO_CASE_FILE_ID']; $penneoErrorFieldId = PodioConfig::$podio_field_id['CONTRACT']['PENNEO_ERROR']; $case_field_id = $this->getPodioItemField($contract_item_id, $penneoCaseFileFieldId); $penneoApp->deleteCaseFile($case_field_id[0]['value']); // delete case file $fields[$penneoCaseFileFieldId] = NULL; $fields[$penneoErrorFieldId] = NULL; $this->updatePodioItem($contract_item_id, $fields, ['silent' => TRUE, 'hook' => FALSE]); $comment = "> Penneo signing process is cancelled"; $this->putItemComment($contract_item_id, $comment); Log::info('Case File ' . $case_field_id[0]['value'] . ' is Deleted'); } else { // Send to Penneo $studentDetails = $this->getStudentItemDetails($contract_item_details['student_item_id']); if (!NULL == $studentDetails['signer_email']) { // Check whether signer email id is given if (!filter_var($studentDetails['signer_email'], FILTER_VALIDATE_EMAIL)) { // Check whether signer have a valid email id $app_name = PodioConfig::$app_name_settings; $podioApp = new PodioController(); $podioApp->podioAppAuthentication($app_name); $errorFieldId = PodioConfig::$podio_field_id['SETTINGS']['ERROR_3_INVALID_MAIL_ID']; $getErrorMessage = $this->getPodioItemField($contract_item_details['settings_id'], $errorFieldId); $error = $getErrorMessage[0]['value']; // Report Error : Invalid signer email format $app_name = PodioConfig::$app_name_contract; $podioApp = new PodioController(); $podioApp->podioAppAuthentication($app_name); $this->updateFieldPenneoStatusInContractApp($updateStatus = 6, $contract_item_id, $error); exit; } $caseFile = $penneoApp->sendDocumentToSign($studentDetails, $contract_item_details); $penneoCaseFileFieldId = PodioConfig::$podio_field_id['CONTRACT']['PENNEO_CASE_FILE_ID']; $penneoErrorFieldId = PodioConfig::$podio_field_id['CONTRACT']['PENNEO_ERROR']; $fields[$penneoCaseFileFieldId] = (string)$caseFile; $fields[$penneoErrorFieldId] = NULL; $app_name = PodioConfig::$app_name_contract; $podioApp = new PodioController(); $podioApp->podioAppAuthentication($app_name); $this->updatePodioItem($contract_item_id, $fields, ['silent' => TRUE, 'hook' => FALSE]); $comment = "> Document send to {$studentDetails['signer_email']}"; $this->putItemComment($contract_item_id, $comment); Log::info("Hook Fired Completed"); Log::info("-------------------------------------------------------------------------------------"); } else { // Report Error : signer email id not given $app_name = PodioConfig::$app_name_settings; $podioApp = new PodioController(); $podioApp->podioAppAuthentication($app_name); $errorFieldId = PodioConfig::$podio_field_id['SETTINGS']['ERROR_2_NO_MAIL_ID']; $getErrorMessage = $this->getPodioItemField($contract_item_details['settings_id'], $errorFieldId); $error = $getErrorMessage[0]['value']; $app_name = PodioConfig::$app_name_contract; $podioApp = new PodioController(); $podioApp->podioAppAuthentication($app_name); $this->updateFieldPenneoStatusInContractApp($updateStatus = 6, $contract_item_id, $error); exit; } } } }else{ return false; } } /** * Update Penneo Status Filed in Contract App * @param $status_id - Status id to update * @param $item_id * @param $message - Message to Update */ public function updateFieldPenneoStatusInContractApp($status_id, $item_id, $message) { try { $status_field_id = PodioConfig::$podio_field_id['CONTRACT']['PENNEO_STATUS']; $error_field_id = PodioConfig::$podio_field_id['CONTRACT']['PENNEO_ERROR']; $fields[$status_field_id] = $status_id; $message ? $fields[$error_field_id] = $message : ''; $this->updatePodioItem($item_id, $fields, ['silent' => TRUE, 'hook' => FALSE]); Log::info("Podio Status Field Updated of Item $item_id with status $status_id"); if ($message) Log::info("Message : " . $message); } catch (PodioError $podioError) { Log::info(" PodioError : Podio Penneo Status Field Update :- PodioController ( updateFieldPenneoStatus )"); exit; } } /** * Replace old file with new Signed files * @param $files * @param $item_id */ public function updateFileChange($files, $item_id) { $app_name = PodioConfig::$app_name_contract; $podioApp = new PodioController(); $podioApp->podioSetup(); $podioApp->podioAppAuthentication($app_name); $contractDetails = $podioApp->getContractDetails($item_id); foreach ($files as $key => $file) { $file['server_path'] = storage_path("docs/penneo/" . $file['name']); $upload_file = $this->uploadFileToPodio($file['server_path'], $file['name']); //upload to podio $this->replaceWithUploadFile($upload_file, $contractDetails['file'][$key]['file_id']); // replace in item } $comment = "> Signed document attached to Podio "; $this->putItemComment($item_id, $comment); Log::info("Files Replaced in Item " . $item_id); } /** * Get details from Penneo Settings app * @param $settingsId - Item id * @return mixed */ public function getPenneoSettingsFromPodio($settingsId) { $app_name = PodioConfig::$app_name_settings; $podioApp = new PodioController(); $podioApp->podioAppAuthentication($app_name); $settingsDetails = array('item_id' => $settingsId, 'type' => 'admin'); $settingsDetails['signer_name'] = $settingsDetails['signer_company_name'] = $settingsDetails['signer_role'] = $settingsDetails['signer_email'] = $settingsDetails['initial_mail_subject'] = $settingsDetails['initial_mail_content'] = $settingsDetails['final_mail_subject'] = $settingsDetails['final_mail_content'] = $settingsDetails['mail_interval'] = NULL; $item = PodioItem::get((int)$settingsId); foreach ($item->fields as $field) switch ($field->field_id) { case PodioConfig::$podio_field_id['SETTINGS']['ADMIN_NAME']: $settingsDetails['signer_name'] = $field->values; break; case PodioConfig::$podio_field_id['SETTINGS']['COMPANY_NAME']: $settingsDetails['signer_company_name'] = $field->values; break; case PodioConfig::$podio_field_id['SETTINGS']['ADMIN_ROLE']: $settingsDetails['signer_role'] = $field->values; break; case PodioConfig::$podio_field_id['SETTINGS']['ADMIN_EMAIL']: $settingsDetails['signer_email'] = $field->values[0]['value']; break; case PodioConfig::$podio_field_id['SETTINGS']['INITIAL_MAIL_SUBJECT']: $settingsDetails['initial_mail_subject'] = $field->values; break; case PodioConfig::$podio_field_id['SETTINGS']['INITIAL_MAIL_CONTENT']: $content = $field->values; $content = preg_replace("/&#?[a-z0-9]+;/i", "", $content); $content = str_replace("</p>", "\n", $content); $content = str_replace("<br />", "\n", $content); $settingsDetails['initial_mail_content'] = strip_tags($content); break; case PodioConfig::$podio_field_id['SETTINGS']['FINAL_MAIL_SUBJECT']: $settingsDetails['final_mail_subject'] = $field->values; break; case PodioConfig::$podio_field_id['SETTINGS']['FINAL_MAIL_CONTENT']: $content = $field->values; $content = preg_replace("/&#?[a-z0-9]+;/i", "", $content); $content = str_replace("</p>", "\n", $content); $content = str_replace("<br />", "\n", $content); $settingsDetails['final_mail_content'] = strip_tags($content); break; case PodioConfig::$podio_field_id['SETTINGS']['MAIL_INTERVALS']: $settingsDetails['mail_interval'] = (int)$field->values; break; } return $settingsDetails; } /** * Just for testing */ public function test() { echo "hy"; // die("Access Restricted...!!!"); $app_name = PodioConfig::$app_name_contract; $podioApp = new PodioController(); $podioApp->podioSetup(); $podioApp->podioAppAuthentication($app_name); $this->statusChange(635845687, 20); } }
Edit
Download
Unzip
Chmod
Delete