Conf->WFconf['defaulttheme']}/images/edit.svg\" border=\"0\">"; $sql = "SELECT aa.id, aa.id, aa.bezeichnung, if(aa.aktiv = 1, 'ja','nein') as aktiv, aa.id FROM `api_account` AS `aa` "; $fastcount = "SELECT COUNT(`aa`.`id`) FROM `api_account` AS `aa`"; break; } $erg = []; foreach($erlaubtevars as $k => $v) { if(isset($$v)) { $erg[$v] = $$v; } } return $erg; } /** * Api_account constructor. * * @param Application $app * @param bool $intern */ public function __construct($app, $intern = false) { $this->app=$app; if($intern) { return; } $this->app->ActionHandlerInit($this); $this->app->ActionHandler("create","Api_AccountCreate"); $this->app->ActionHandler("edit","Api_AccountEdit"); $this->app->ActionHandler("list","Api_AccountList"); $this->app->ActionHandler("delete","Api_AccountDelete"); $this->app->DefaultActionHandler('list'); $this->app->ActionHandlerListen($app); } function Api_AccountCreate(){ } function Api_AccountEdit(){ } public function Api_AccountDelete(){ $id = $this->app->Secure->GetGET('id'); $this->app->DB->Delete(sprintf('DELETE FROM `api_account` WHERE `id` = %d', $id)); $this->app->Location->execute('index.php?module=api_account&action=list'); } /** * @return JsonResponse */ public function HandleGetAjaxAction() { $id = (int)$this->app->Secure->GetPOST('id'); if($id === 0) { $data = [ 'aktiv' => 0, 'id' => '', 'bezeichnung' => '', 'projekt' => '', 'remotedomain' => '', 'initkey' => '', 'importwarteschlange' => 0, 'importwarteschlange_name' => '', 'event_url' => '', 'cleanutf8' => 0, 'apitempkey' => '', 'ishtmltransformation' => 0, ]; return new JsonResponse($data); } if($id > 0) { $data = $this->app->DB->SelectRow( sprintf( "SELECT a.id, a.bezeichnung, a.aktiv, p.abkuerzung AS `projekt`, a.remotedomain, a.initkey, a.importwarteschlange, a.importwarteschlange_name, a.cleanutf8, a.event_url, a.permissions, a.ishtmltransformation FROM `api_account` AS `a` LEFT JOIN `projekt` AS `p` ON a.projekt = p.id WHERE a.id = %d", $id ) ); /** @var Api $api */ $api = $this->app->loadModule('api'); $data['apitempkey'] = $api->generateHashFromDomainAndKey($data['initkey'], $data['remotedomain']); if(!empty($data)) { return new JsonResponse($data); } } return new JsonResponse(['error'=>'Account nicht gefunden'], JsonResponse::HTTP_BAD_REQUEST); } /** * @return JsonResponse */ public function HandleSaveAjaxAction() { if(!$this->app->erp->RechteVorhanden('api_account', 'edit')) { return new JsonResponse(['error'=>'Fehlende Rechte'], JsonResponse::HTTP_BAD_REQUEST); } $id = (int)$this->app->Secure->GetPOST('id'); $bezeichnung = $this->app->Secure->GetPOST('bezeichnung'); if(empty($bezeichnung)) { return new JsonResponse(['error'=>'Bitte füllen Sie die Bezeichnung aus'], JsonResponse::HTTP_BAD_REQUEST); } $projekt = (string)$this->app->Secure->GetPOST('projekt'); if($projekt !== ''){ $projekt = (int)$this->app->erp->ReplaceProjekt(1, $projekt, 1); } else { $projekt = 0; } $aktiv = (int)(bool)$this->app->Secure->GetPOST('aktiv'); $importwarteschlange = (int)(bool)$this->app->Secure->GetPOST('importwarteschlange'); $cleanutf8 = (int)(bool)$this->app->Secure->GetPOST('cleanutf8'); $remotedomain = $this->app->Secure->GetPOST('remotedomain'); $initkey = $this->app->Secure->GetPOST('initkey'); $importwarteschlange_name = $this->app->Secure->GetPOST('importwarteschlange_name'); $event_url = $this->app->Secure->GetPOST('event_url'); $isHtmlTransformation = (int)(bool)$this->app->Secure->GetPOST('ishtmltransformation'); $api_permissions = $this->prepareApiPermissions($this->app->Secure->GetPOST('api_permissions')); if($id <= 0) { $this->app->DB->Insert( sprintf( "INSERT INTO `api_account` (`bezeichnung`, `initkey`, `importwarteschlange_name`, `event_url`, `remotedomain`, `aktiv`, `importwarteschlange`, `cleanutf8`, `uebertragung_account`, `projekt`, `permissions`, `ishtmltransformation`) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, %d, '%s', %d) ", $bezeichnung, $initkey, $importwarteschlange_name, $event_url, $remotedomain, $aktiv, $importwarteschlange, $cleanutf8, $projekt, $api_permissions, $isHtmlTransformation ) ); $id = (int)$this->app->DB->GetInsertID(); if($id){ $data = ['success' => true, 'id' => $id]; return new JsonResponse($data); } return new JsonResponse(['error'=>'Account konnte nicht erstellt werden'], JsonResponse::HTTP_BAD_REQUEST); } $data = $this->app->DB->SelectRow( sprintf( "SELECT a.id, a.bezeichnung, a.aktiv, p.abkuerzung AS `projekt`, a.remotedomain, a.initkey, a.importwarteschlange, a.importwarteschlange_name, a.cleanutf8, a.event_url, a.permissions, a.ishtmltransformation FROM `api_account` AS `a` LEFT JOIN `projekt` AS `p` ON a.projekt = p.id WHERE a.id = %d", $id ) ); if(empty($data)) { return new JsonResponse(['error'=>'Account nicht gefunden'], JsonResponse::HTTP_BAD_REQUEST); } $this->app->DB->Update( sprintf( "UPDATE `api_account` SET `bezeichnung` = '%s', `initkey` = '%s', `importwarteschlange_name` = '%s', `event_url` = '%s', `remotedomain` = '%s', `aktiv` = %d, `importwarteschlange` = %d, `cleanutf8` = %d, `uebertragung_account` = 0, `projekt` = %d , `permissions` = '%s', `ishtmltransformation` = %d WHERE `id` = %d", $bezeichnung, $initkey, $importwarteschlange_name, $event_url, $remotedomain, $aktiv, $importwarteschlange, $cleanutf8, $projekt, $api_permissions, $isHtmlTransformation, $id ) ); if(empty($this->app->DB->error())) { $data = ['success' => true, 'id' => $id]; return new JsonResponse($data); } return new JsonResponse(['error'=>'Account konnte nicht geändert werden'], JsonResponse::HTTP_BAD_REQUEST); } private function prepareApiPermissions(array $apiPermissions){ $cleanedPermissions = []; foreach ($apiPermissions as $permission => $value){ if($value === 'true'){ $cleanedPermissions[] = $permission; } } return json_encode($cleanedPermissions); } public function Api_AccountList(){ $cmd = $this->app->Secure->GetGET('cmd'); if($cmd === 'get') { return $this->HandleGetAjaxAction(); } if($cmd === 'save') { return $this->HandleSaveAjaxAction(); } $apiPermissions = $this->app->DB->SelectArr("SELECT * FROM `api_permission`"); if (empty($apiPermissions)) { $api = $this->app->loadModule('api'); $api->fillApiPermissions(); $apiPermissions = $this->app->DB->SelectArr("SELECT * FROM `api_permission`"); } $groupedApiPermissions = []; foreach ($apiPermissions as $apiPermission){ $groupedApiPermissions[$apiPermission['group']][] =$apiPermission; } $apiPermissionsHtml = ''; foreach ($groupedApiPermissions as $group => $permissions) { $apiPermissionsHtml .= ''; $apiPermissionsHtml .= "{$group}"; $apiPermissionsHtml .= ""; foreach ($permissions as $permission){ $apiPermissionsHtml .= ""; $apiPermissionsHtml .= "
"; } $apiPermissionsHtml .= ""; $apiPermissionsHtml .= ''; } $this->app->YUI->TableSearch('TAB1','api_account_list', 'show','','',basename(__FILE__), __CLASS__); $this->app->erp->MenuEintrag('#', 'Neu'); $this->app->erp->MenuEintrag('index.php?module=api_account&action=list', 'Übersicht'); $this->app->erp->Headlines('API Account'); $this->app->Tpl->Set('API_PERMISSIONS_HTML', $apiPermissionsHtml); $this->app->YUI->Autocomplete('projekt', 'projektname', 1); $this->app->Tpl->Parse('PAGE','api_account_list.tpl'); } }