diff --git a/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts b/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts index a7880103e324e7c4769c618ab8a4e13309b9a061..0f915c979056bc386c454db733888b8b9d4955f0 100755 --- a/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/administration/template-administration.component.ts @@ -9,32 +9,35 @@ declare function $j(selector: any): any; declare var tinymce: any; declare var angularGlobals: any; + @Component({ templateUrl: "../../../../Views/template-administration.component.html", providers: [NotificationService] }) export class TemplateAdministrationComponent implements OnInit { - mobileQuery: MediaQueryList; - private _mobileQueryListener: () => void; - lang: any = LANG; - coreUrl: string; - creationMode: boolean; - template: any = {}; - statuses: any[] = []; - actionPagesList: any[] = []; - categoriesList: any[] = []; - keywordsList: any[] = []; - defaultTemplatesList: any; - attachmentTypesList: any; - datasourcesList: any; - jnlpValue: any = {}; - extensionModels:any[] = []; - buttonFileName: any = this.lang.importFile; - lockFound: boolean = false; - intervalLockFile: any; + private _mobileQueryListener : () => void; + mobileQuery : MediaQueryList; + + coreUrl : string; + lang : any = LANG; + loading : boolean = false; + + creationMode : boolean; + template : any = {}; + statuses : any[] = []; + actionPagesList : any[] = []; + categoriesList : any[] = []; + keywordsList : any[] = []; + defaultTemplatesList : any; + attachmentTypesList : any; + datasourcesList : any; + jnlpValue : any = {}; + extensionModels : any[] = []; + buttonFileName : any = this.lang.importFile; + lockFound : boolean = false; + intervalLockFile : any; - loading: boolean = false; constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, private zone: NgZone, private route: ActivatedRoute, private router: Router, private notify: NotificationService) { $j("link[href='merged_css.php']").remove(); @@ -93,7 +96,40 @@ export class TemplateAdministrationComponent implements OnInit { }); } - setInitialValue(data:any){ + initMce() { + setTimeout(() => { + tinymce.remove('textarea'); + //LOAD EDITOR TINYMCE for MAIL SIGN + tinymce.baseURL = "../../node_modules/tinymce"; + tinymce.suffix = '.min'; + tinymce.init({ + selector: "textarea#templateHtml", + statusbar: false, + language: "fr_FR", + language_url: "tools/tinymce/langs/fr_FR.js", + height: "200", + plugins: [ + "textcolor", + "autoresize" + ], + external_plugins: { + 'bdesk_photo': "../../apps/maarch_entreprise/tools/tinymce/bdesk_photo/plugin.min.js" + }, + menubar: false, + toolbar: "undo | bold italic underline | alignleft aligncenter alignright | bdesk_photo | forecolor", + theme_buttons1_add: "fontselect,fontsizeselect", + theme_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator", + theme_buttons2_add: "separator,insertdate,inserttime,preview,separator,forecolor,backcolor", + theme_buttons3_add_before: "tablecontrols,separator", + theme_buttons3_add: "separator,print,separator,ltr,rtl,separator,fullscreen,separator,insertlayer,moveforward,movebackward,absolut", + theme_toolbar_align: "left", + theme_advanced_toolbar_location: "top", + theme_styles: "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1" + }); + }, 20); + } + + setInitialValue(data:any) { this.extensionModels = []; data.templatesModels.forEach((model: any) => { if (this.extensionModels.indexOf(model.fileExt) == -1) { @@ -130,45 +166,12 @@ export class TemplateAdministrationComponent implements OnInit { }, 0); } - initMce() { - setTimeout(() => { - tinymce.remove('textarea'); - //LOAD EDITOR TINYMCE for MAIL SIGN - tinymce.baseURL = "../../node_modules/tinymce"; - tinymce.suffix = '.min'; - tinymce.init({ - selector: "textarea#templateHtml", - statusbar: false, - language: "fr_FR", - language_url: "tools/tinymce/langs/fr_FR.js", - height: "200", - plugins: [ - "textcolor", - "autoresize" - ], - external_plugins: { - 'bdesk_photo': "../../apps/maarch_entreprise/tools/tinymce/bdesk_photo/plugin.min.js" - }, - menubar: false, - toolbar: "undo | bold italic underline | alignleft aligncenter alignright | bdesk_photo | forecolor", - theme_buttons1_add: "fontselect,fontsizeselect", - theme_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator", - theme_buttons2_add: "separator,insertdate,inserttime,preview,separator,forecolor,backcolor", - theme_buttons3_add_before: "tablecontrols,separator", - theme_buttons3_add: "separator,print,separator,ltr,rtl,separator,fullscreen,separator,insertlayer,moveforward,movebackward,absolut", - theme_toolbar_align: "left", - theme_advanced_toolbar_location: "top", - theme_styles: "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1" - }); - }, 20); - } - clickOnUploader(id: string) { $j('#' + id).click(); } uploadFileTrigger(fileInput: any) { - this.template.userUniqueId = null; + this.template.jnlpUniqueId = null; if (fileInput.target.files && fileInput.target.files[0]) { this.template.uploadedFile = {}; this.template.uploadedFile.name = fileInput.target.files[0].name; @@ -214,19 +217,19 @@ export class TemplateAdministrationComponent implements OnInit { this.jnlpValue.cookies = document.cookie; this.http.post(this.coreUrl + 'rest/jnlp', this.jnlpValue) - .subscribe((data: any) => { - this.template.userUniqueId = data.userUniqueId; - this.fileToImport(); - window.location.href = this.coreUrl + 'rest/jnlp?fileName=' + data.generatedJnlp; - this.checkLockFile(); - }, (err) => { - this.notify.error(err.error.errors); - }); + .subscribe((data: any) => { + this.template.jnlpUniqueId = data.jnlpUniqueId; + this.fileToImport(); + window.location.href = this.coreUrl + 'rest/jnlp?fileName=' + data.generatedJnlp; + this.checkLockFile(); + }, (err) => { + this.notify.error(err.error.errors); + }); } - checkLockFile(){ + checkLockFile() { this.intervalLockFile = setInterval(() => { - this.http.get(this.coreUrl + 'rest/jnlp/lock/' + this.template.userUniqueId) + this.http.get(this.coreUrl + 'rest/jnlp/lock/' + this.template.jnlpUniqueId) .subscribe((data: any) => { this.lockFound = data.lockFileFound; if(!this.lockFound){ @@ -236,8 +239,7 @@ export class TemplateAdministrationComponent implements OnInit { }, 1000) } - duplicateTemplate() - { + duplicateTemplate() { let r = confirm(this.lang.confirmDuplicate); if (r) { @@ -253,14 +255,14 @@ export class TemplateAdministrationComponent implements OnInit { onSubmit() { this.template.entities = $j('#jstree').jstree(true).get_checked(); - if(this.template.template_target!='notifications'){ - this.template.template_datasource=='letterbox_attachment'; + if (this.template.template_target != 'notifications') { + this.template.template_datasource = 'letterbox_attachment'; } - if(this.creationMode && this.template.template_style != 'uploadFile' && !this.template.userUniqueId && this.template.template_type == 'OFFICE'){ + if (this.creationMode && this.template.template_style != 'uploadFile' && !this.template.jnlpUniqueId && this.template.template_type == 'OFFICE') { alert(this.lang.editModelFirst); return; } - if (this.template.template_type=='HTML'){ + if (this.template.template_type=='HTML') { this.template.template_content = tinymce.get('templateHtml').getContent(); } if (this.creationMode) { @@ -288,41 +290,36 @@ export class TemplateAdministrationComponent implements OnInit { } } - displayDatasources(datasource:any) - { - if(datasource.target=='notification' && this.template.template_target == 'notifications'){ + displayDatasources(datasource:any) { + if (datasource.target=='notification' && this.template.template_target == 'notifications') { return true; - } else if(datasource.target=='document' && this.template.template_target != 'notifications'){ + } else if (datasource.target=='document' && this.template.template_target != 'notifications') { return true; } return false; } - updateTemplateType() - { - if(this.template.template_target=='attachments'){ - this.template.template_type='OFFICE'; - } else if(this.template.template_target=='notifications' || this.template.template_target=='doctypes' || this.template.template_target=='sendmail'){ - this.template.template_type='HTML'; + updateTemplateType() { + if (this.template.template_target == 'attachments') { + this.template.template_type = 'OFFICE'; + } else if (this.template.template_target == 'notifications' || this.template.template_target == 'doctypes' || this.template.template_target == 'sendmail') { + this.template.template_type = 'HTML'; this.initMce(); - } else if (this.template.template_target=='notes') { - this.template.template_type='TXT'; + } else if (this.template.template_target == 'notes') { + this.template.template_type = 'TXT'; } } - fileImported() - { + fileImported() { this.buttonFileName = this.template.uploadedFile.name; } - fileToImport() - { + fileToImport() { this.buttonFileName = this.lang.importFile; } - resetFileUploaded() - { + resetFileUploaded() { this.fileToImport(); this.template.uploadedFile = null; } -} \ No newline at end of file +} diff --git a/rest/index.php b/rest/index.php index d28985d849f41a7f5587baefc423c68856f0a976..cfa3c4250b316dd58a3c990b519e8f1aca1040f3 100755 --- a/rest/index.php +++ b/rest/index.php @@ -156,8 +156,8 @@ $app->get('/histories/users/{userSerialId}', \History\controllers\HistoryControl //Jnlp $app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp'); $app->get('/jnlp', \ContentManagement\controllers\JnlpController::class . ':renderJnlp'); -$app->post('/jnlp/{userUniqueId}', \ContentManagement\controllers\JnlpController::class . ':processJnlp'); -$app->get('/jnlp/lock/{userUniqueId}', \ContentManagement\controllers\JnlpController::class . ':isLockFileExisting'); +$app->post('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':processJnlp'); +$app->get('/jnlp/lock/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':isLockFileExisting'); //Links $app->get('/links/resId/{resId}', \Link\controllers\LinkController::class . ':getByResId'); diff --git a/src/app/contentManagement/controllers/JnlpController.php b/src/app/contentManagement/controllers/JnlpController.php index 9a272a8f79c5c67e0d7d46721e2e346a4fb5da36..018a667f3f2d3e03e27d9b179477faec16af8890 100644 --- a/src/app/contentManagement/controllers/JnlpController.php +++ b/src/app/contentManagement/controllers/JnlpController.php @@ -32,8 +32,8 @@ class JnlpController $coreUrl = str_replace('rest/', '', \Url::coreurl()); $tmpPath = CoreConfigModel::getTmpPath(); - $userUniqueId = DatabaseModel::uniqueId(); - $jnlpFileName = $GLOBALS['userId'] . '_maarchCM_' . $userUniqueId; + $jnlpUniqueId = DatabaseModel::uniqueId(); + $jnlpFileName = $GLOBALS['userId'] . '_maarchCM_' . $jnlpUniqueId; $jnlpFileNameExt = $jnlpFileName . '.jnlp'; $allCookies = ''; @@ -125,7 +125,7 @@ class JnlpController $newAttribute->value = 'com.maarch.MaarchCM'; $tagApplication->appendChild($newAttribute); - $tagArg1 = $jnlpDocument->createElement('argument', $coreUrl . 'rest/jnlp/' . $userUniqueId); + $tagArg1 = $jnlpDocument->createElement('argument', $coreUrl . 'rest/jnlp/' . $jnlpUniqueId); $tagArg2 = $jnlpDocument->createElement('argument', $data['objectType']); $tagArg3 = $jnlpDocument->createElement('argument', $data['table']); $tagArg4 = $jnlpDocument->createElement('argument', $data['objectId']); @@ -175,7 +175,7 @@ class JnlpController fopen($tmpPath . $jnlpFileName . '.lck', 'w+'); - return $response->withJson(['generatedJnlp' => $jnlpFileNameExt, 'userUniqueId' => $userUniqueId]); + return $response->withJson(['generatedJnlp' => $jnlpFileNameExt, 'jnlpUniqueId' => $jnlpUniqueId]); } public function renderJnlp(Request $request, Response $response) @@ -209,7 +209,7 @@ class JnlpController if ($data['objectType'] == 'templateCreation') { $explodeFile = explode('.', $data['objectId']); $ext = $explodeFile[count($explodeFile) - 1]; - $newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['userUniqueId']}.{$ext}"; + $newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}"; $pathToCopy = $data['objectId']; } elseif ($data['objectType'] == 'templateModification') { @@ -218,7 +218,7 @@ class JnlpController $explodeFile = explode('.', $template['template_file_name']); $ext = $explodeFile[count($explodeFile) - 1]; - $newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['userUniqueId']}.{$ext}"; + $newFileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}"; $pathToCopy = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $template['template_path']) . $template['template_file_name']; } else { @@ -259,14 +259,14 @@ class JnlpController $encodedFileContent = str_replace(' ', '+', $data['fileContent']); $ext = str_replace(["\\", "/", '..'], '', $data['fileExtension']); $fileContent = base64_decode($encodedFileContent); - $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['userUniqueId']}.{$ext}"; + $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$aArgs['jnlpUniqueId']}.{$ext}"; $file = fopen($tmpPath . $fileOnTmp, 'w'); fwrite($file, $fileContent); fclose($file); if (!empty($data['step']) && $data['step'] == 'end') { - unlink($tmpPath . $GLOBALS['userId'] . '_maarchCM_' . $aArgs['userUniqueId'] . '.lck'); + unlink($tmpPath . $GLOBALS['userId'] . '_maarchCM_' . $aArgs['jnlpUniqueId'] . '.lck'); } $result = ['END_MESSAGE' => 'Update ok']; @@ -295,7 +295,7 @@ class JnlpController public function isLockFileExisting(Request $request, Response $response, array $aArgs) { $tmpPath = CoreConfigModel::getTmpPath(); - $lockFileName = "{$GLOBALS['userId']}_maarchCM_{$aArgs['userUniqueId']}.lck"; + $lockFileName = "{$GLOBALS['userId']}_maarchCM_{$aArgs['jnlpUniqueId']}.lck"; $fileFound = false; if (file_exists($tmpPath . $lockFileName)) { diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php index 5c511528b6b325ad28243a153a8c7526289225c0..8702972c8924966d060d62bb7f3b727275217fc9 100644 --- a/src/app/template/controllers/TemplateController.php +++ b/src/app/template/controllers/TemplateController.php @@ -107,15 +107,15 @@ class TemplateController } if ($data['template_type'] == 'OFFICE') { - if (empty($data['userUniqueId']) && empty($data['uploadedFile'])) { + if (empty($data['jnlpUniqueId']) && empty($data['uploadedFile'])) { return $response->withStatus(400)->withJson(['errors' => 'Template file is missing']); } - if (!empty($data['userUniqueId'])) { + if (!empty($data['jnlpUniqueId'])) { if (!Validator::stringType()->notEmpty()->validate($data['template_style'])) { return $response->withStatus(400)->withJson(['errors' => 'Template style is missing']); } $explodeStyle = explode(':', $data['template_style']); - $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]); + $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['jnlpUniqueId']}." . strtolower($explodeStyle[0]); } else { if (empty($data['uploadedFile']['base64']) || empty($data['uploadedFile']['name'])) { return $response->withStatus(400)->withJson(['errors' => 'Uploaded file is missing']); @@ -186,13 +186,13 @@ class TemplateController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - if ($data['template_type'] == 'OFFICE' && (!empty($data['userUniqueId']) || !empty($data['uploadedFile']))) { - if (!empty($data['userUniqueId'])) { + if ($data['template_type'] == 'OFFICE' && (!empty($data['jnlpUniqueId']) || !empty($data['uploadedFile']))) { + if (!empty($data['jnlpUniqueId'])) { if (!empty($template['template_style']) && !Validator::stringType()->notEmpty()->validate($data['template_style'])) { return $response->withStatus(400)->withJson(['errors' => 'Template style is missing']); } $explodeStyle = explode('.', $data['template_file_name']); - $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[count($explodeStyle) - 1]); + $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['jnlpUniqueId']}." . strtolower($explodeStyle[count($explodeStyle) - 1]); } else { if (empty($data['uploadedFile']['base64']) || empty($data['uploadedFile']['name'])) { return $response->withStatus(400)->withJson(['errors' => 'Uploaded file is missing']); @@ -233,7 +233,7 @@ class TemplateController } } unset($data['uploadedFile']); - unset($data['userUniqueId']); + unset($data['jnlpUniqueId']); unset($data['entities']); TemplateModel::update(['set' => $data, 'where' => ['template_id = ?'], 'data' => [$aArgs['id']]]); diff --git a/src/core/controllers/CoreController.php b/src/core/controllers/CoreController.php index b69475ed116b85bd700ea243acab7a5d2aae3dcb..da934ec11abeaf5216ac9f54d21d7e79367e15d9 100644 --- a/src/core/controllers/CoreController.php +++ b/src/core/controllers/CoreController.php @@ -56,18 +56,16 @@ class CoreController public static function getAdministration(Request $request, Response $response) { + if (!ServiceModel::hasService(['id' => 'admin', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + if ($GLOBALS['userId'] == 'superadmin') { $administration = []; -// $administrationMenu = ServiceModel::getApplicationAdministrationMenuByXML(); $administrationApplication = ServiceModel::getApplicationAdministrationServicesByXML(); $administrationModule = ServiceModel::getModulesAdministrationServicesByXML(); $administration['administrations'] = array_merge_recursive($administrationApplication, $administrationModule); -// $administration = array_merge_recursive($administration, $administrationMenu); } else { - if (!ServiceModel::hasService(['id' => 'admin', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - $administration = ServiceModel::getAdministrationServicesByUserId(['userId' => $GLOBALS['userId']]); }