PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/phpmyfaq/admin/record.edit.php

https://github.com/cyrke/phpMyFAQ
PHP | 944 lines | 786 code | 90 blank | 68 comment | 99 complexity | 866134481180213cd02b48d08df0108a MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * The FAQ record editor.
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Administration
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @copyright 2003-2012 phpMyFAQ Team
  15. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  16. * @link http://www.phpmyfaq.de
  17. * @since 2003-02-23
  18. */
  19. if (!defined('IS_VALID_PHPMYFAQ')) {
  20. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  21. exit();
  22. }
  23. // Re-evaluate $user
  24. $user = PMF_User_CurrentUser::getFromSession($faqConfig);
  25. if (($permission['editbt']|| $permission['addbt']) && !PMF_Db::checkOnEmptyTable('faqcategories')) {
  26. $category = new PMF_Category($faqConfig, false);
  27. $category->setUser($currentAdminUser);
  28. $category->setGroups($currentAdminGroups);
  29. $category->buildTree();
  30. $categoryHelper = new PMF_Helper_Category();
  31. $categoryHelper->setCategory($category);
  32. $selectedCategory = '';
  33. $categories = array();
  34. $faqData = array(
  35. 'id' => 0,
  36. 'lang' => $LANGCODE,
  37. 'revision_id' => 0,
  38. 'title' => '',
  39. 'dateStart' => '',
  40. 'dateEnd' => ''
  41. );
  42. $tagging = new PMF_Tags($faqConfig);
  43. $date = new PMF_Date($faqConfig);
  44. if ('takequestion' === $action) {
  45. $questionId = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  46. $question = $faq->getQuestion($questionId);
  47. $selectedCategory = $question['category_id'];
  48. $faqData['title'] = $question['question'];
  49. $notifyUser = $question['username'];
  50. $notifyEmail = $question['email'];
  51. $categories = array(
  52. 'category_id' => $selectedCategory,
  53. 'category_lang' => $faqData['lang']
  54. );
  55. } else {
  56. $questionId = 0;
  57. $notifyUser = '';
  58. $notifyEmail = '';
  59. }
  60. if ('editpreview' === $action) {
  61. $faqData['id'] = PMF_Filter::filterInput(INPUT_POST, 'id', FILTER_VALIDATE_INT);
  62. if (!is_null($faqData['id'])) {
  63. $queryString = 'saveentry&amp;id=' . $faqData['id'];
  64. } else {
  65. $queryString = 'insertentry';
  66. }
  67. $faqData['lang'] = PMF_Filter::filterInput(INPUT_POST, 'lang', FILTER_SANITIZE_STRING);
  68. $selectedCategory = isset($_POST['rubrik']) ? $_POST['rubrik'] : null;
  69. if (is_array($selectedCategory)) {
  70. foreach ($selectedCategory as $cats) {
  71. $categories[] = array('category_id' => $cats, 'category_lang' => $faqData['lang']);
  72. }
  73. }
  74. $faqData['active'] = PMF_Filter::filterInput(INPUT_POST, 'active', FILTER_SANITIZE_STRING);
  75. $faqData['keywords'] = PMF_Filter::filterInput(INPUT_POST, 'keywords', FILTER_SANITIZE_STRING);
  76. $faqData['title'] = PMF_Filter::filterInput(INPUT_POST, 'thema', FILTER_SANITIZE_STRING);
  77. $faqData['content'] = PMF_Filter::filterInput(INPUT_POST, 'content', FILTER_SANITIZE_SPECIAL_CHARS);
  78. $faqData['author'] = PMF_Filter::filterInput(INPUT_POST, 'author', FILTER_SANITIZE_STRING);
  79. $faqData['email'] = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
  80. $faqData['comment'] = PMF_Filter::filterInput(INPUT_POST, 'comment', FILTER_SANITIZE_STRING);
  81. $faqData['solution_id'] = PMF_Filter::filterInput(INPUT_POST, 'solution_id', FILTER_VALIDATE_INT);
  82. $faqData['revision_id'] = PMF_Filter::filterInput(INPUT_POST, 'revision_id', FILTER_VALIDATE_INT, 0);
  83. $faqData['sticky'] = PMF_Filter::filterInput(INPUT_POST, 'sticky', FILTER_VALIDATE_INT);
  84. $faqData['tags'] = PMF_Filter::filterInput(INPUT_POST, 'tags', FILTER_SANITIZE_STRING);
  85. $faqData['changed'] = PMF_Filter::filterInput(INPUT_POST, 'changed', FILTER_SANITIZE_STRING);
  86. $faqData['dateStart'] = PMF_Filter::filterInput(INPUT_POST, 'dateStart', FILTER_SANITIZE_STRING);
  87. $faqData['dateEnd'] = PMF_Filter::filterInput(INPUT_POST, 'dateEnd', FILTER_SANITIZE_STRING);
  88. $faqData['content'] = html_entity_decode($faqData['content']);
  89. } elseif ('editentry' === $action) {
  90. $id = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  91. $lang = PMF_Filter::filterInput(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
  92. if ((!isset($selectedCategory) && !isset($faqData['title'])) || !is_null($id)) {
  93. $logging = new PMF_Logging($faqConfig);
  94. $logging->logAdmin($user, 'Beitragedit, ' . $id);
  95. $categories = $category->getCategoryRelationsFromArticle($id, $lang);
  96. $faq->getRecord($id, null, true);
  97. $faqData = $faq->faqRecord;
  98. $faqData['tags'] = implode(',', $tagging->getAllTagsById($faqData['id']));
  99. $queryString = 'saveentry&amp;id=' . $faqData['id'];
  100. } else {
  101. $queryString = 'insertentry';
  102. }
  103. } elseif ('copyentry' === $action) {
  104. $faqData['id'] = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  105. $faqData['lang'] = PMF_Filter::filterInput(INPUT_GET, 'lang', FILTER_SANITIZE_STRING);
  106. $faq->language = $faqData['lang'];
  107. $categories = $category->getCategoryRelationsFromArticle($faqData['id'], $faqData['lang']);
  108. $faq->getRecord($faqData['id'], null, true);
  109. $faqData = $faq->faqRecord;
  110. $queryString = 'insertentry';
  111. } else {
  112. $logging = new PMF_Logging($faqConfig);
  113. $logging->logAdmin($user, 'Beitragcreate');
  114. $queryString = 'insertentry';
  115. if (!is_array($categories)) {
  116. $categories = array();
  117. }
  118. }
  119. // Revisions
  120. $selectedRevisionId = PMF_Filter::filterInput(INPUT_POST, 'revisionid_selected', FILTER_VALIDATE_INT);
  121. if (is_null($selectedRevisionId)) {
  122. $selectedRevisionId = $faqData['revision_id'];
  123. }
  124. // User permissions
  125. $userPermission = $faq->getPermission('user', $faqData['id']);
  126. if (count($userPermission) == 0 || $userPermission[0] == -1) {
  127. $allUsers = true;
  128. $restrictedUsers = false;
  129. $userPermission[0] = -1;
  130. } else {
  131. $allUsers = false;
  132. $restrictedUsers = true;
  133. }
  134. // Group permissions
  135. $groupPermission = $faq->getPermission('group', $faqData['id']);
  136. if (count($groupPermission) == 0 || $groupPermission[0] == -1) {
  137. $allGroups = true;
  138. $restrictedGroups = false;
  139. $groupPermission[0] = -1;
  140. } else {
  141. $allGroups = false;
  142. $restrictedGroups = true;
  143. }
  144. // Set data for forms
  145. $faqData['title'] = (isset($faqData['title']) ? PMF_String::htmlspecialchars($faqData['title']) : '');
  146. $faqData['content'] = (isset($faqData['content']) ? trim(PMF_String::htmlentities($faqData['content'])) : '');
  147. $faqData['tags'] = (isset($faqData['tags']) ? PMF_String::htmlspecialchars($faqData['tags']) : '');
  148. $faqData['keywords'] = (isset($faqData['keywords']) ? PMF_String::htmlspecialchars($faqData['keywords']) : '');
  149. $faqData['author'] = (isset($faqData['author']) ? PMF_String::htmlspecialchars($faqData['author']) : $user->getUserData('display_name'));
  150. $faqData['email'] = (isset($faqData['email']) ? PMF_String::htmlspecialchars($faqData['email']) : $user->getUserData('email'));
  151. $faqData['date'] = (isset($faqData['date']) ? $date->format($faqData['date']) : $date->format(date('Y-m-d H:i')));
  152. $faqData['changed'] = (isset($faqData['changed']) ? $faqData['changed'] : '');
  153. if (isset($faqData['comment']) && $faqData['comment'] == 'y') {
  154. $faqData['comment'] = ' checked="checked"';
  155. } elseif ($faqConfig->get('records.defaultAllowComments')) {
  156. $faqData['comment'] = ' checked="checked"';
  157. } else {
  158. $faqData['comment'] = '';
  159. }
  160. // Start header
  161. if (0 !== $faqData['id'] && 'copyentry' !== $action) {
  162. $currentRevision = sprintf(
  163. ' <span class="badge badge-important">%s 1.%d</span> ',
  164. $PMF_LANG['ad_entry_revision'],
  165. $selectedRevisionId
  166. );
  167. printf(
  168. '<header><h2>%s <span class="text-error">%s</span> %s %s</h2></header>',
  169. $PMF_LANG['ad_entry_edit_1'],
  170. (0 === $faqData['id'] ? '' : $faqData['id']),
  171. $PMF_LANG['ad_entry_edit_2'],
  172. $currentRevision
  173. );
  174. } else {
  175. printf(
  176. '<header><h2>%s</h2></header>',
  177. $PMF_LANG['ad_entry_add']
  178. );
  179. }
  180. ?>
  181. <div class="row-fluid">
  182. <!-- Revisions -->
  183. </div>
  184. <div class="row-fluid">
  185. <form id="faqEditor" action="?action=<?php echo $queryString; ?>" method="post">
  186. <input type="hidden" name="revision_id" id="revision_id" value="<?php echo $faqData['revision_id']; ?>" />
  187. <input type="hidden" name="record_id" id="record_id" value="<?php echo $faqData['id']; ?>" />
  188. <input type="hidden" name="csrf" value="<?php echo $user->getCsrfTokenFromSession(); ?>" />
  189. <input type="hidden" name="openQuestionId" id="openQuestionId" value="<?php echo $questionId; ?>" />
  190. <input type="hidden" name="notifyUser" id="notifyUser" value="<?php echo $notifyUser ?>" />
  191. <input type="hidden" name="notifyEmail" id="notifyEmail" value="<?php echo $notifyEmail ?>" />
  192. <!-- main editor window -->
  193. <div class="span8">
  194. <fieldset class="form-inline">
  195. <!-- Question -->
  196. <div class="control-group">
  197. <div class="controls">
  198. <input type="text" name="question" id="question" class="admin-question"
  199. placeholder="<?php echo $PMF_LANG['ad_entry_theme']; ?>" maxlength="255"
  200. value="<?php echo $faqData['title'] ?>" />
  201. </div>
  202. </div>
  203. <!-- Answer -->
  204. <div class="control-group">
  205. <div class="controls">
  206. <noscript>Please enable JavaScript to use the WYSIWYG editor!</noscript>
  207. <textarea id="answer" name="answer" class="span8">
  208. <?php echo $faqData['content'] ?>
  209. </textarea>
  210. </div>
  211. </div>
  212. </fieldset>
  213. <fieldset class="form-horizontal">
  214. <!-- Meta data -->
  215. <?php if ($faqConfig->get('main.enableGoogleTranslation') === true): ?>
  216. <input type="hidden" id="lang" name="lang" value="<?php echo $faqData['lang']; ?>" />
  217. <?php else: ?>
  218. <div class="control-group">
  219. <label class="control-label" for="lang"><?php echo $PMF_LANG["ad_entry_locale"]; ?>:</label>
  220. <div class="controls">
  221. <?php echo PMF_Language::selectLanguages($faqData['lang'], false, array(), 'lang'); ?>
  222. </div>
  223. </div>
  224. <?php endif; ?>
  225. </fieldset>
  226. <fieldset class="form-horizontal">
  227. <!-- Attachments -->
  228. <?php if ($permission['addattachment']): ?>
  229. <div class="control-group">
  230. <label class="control-label"><?php echo $PMF_LANG['ad_menu_attachments'] ?>:</label>
  231. <div class="controls">
  232. <ul class="adminAttachments">
  233. <?php
  234. $attList = PMF_Attachment_Factory::fetchByRecordId($faqConfig, $faqData['id']);
  235. foreach ($attList as $att) {
  236. printf(
  237. '<li><a href="../%s">%s</a> ',
  238. $att->buildUrl(),
  239. $att->getFilename()
  240. );
  241. if ($permission['delattachment']) {
  242. printf(
  243. '<a class="label label-important" href="?action=delatt&amp;record_id=%d&amp;id=%d&amp;lang=%s"><i class="icon-trash icon-white"></i></a>',
  244. $faqData['id'],
  245. $att->getId(),
  246. $faqData['lang']
  247. );
  248. }
  249. echo "</li>\n";
  250. }
  251. ?>
  252. </ul>
  253. <?php
  254. if (0 === $faqData['id']) {
  255. $faqData['id'] = $faqConfig->getDb()->nextId(
  256. PMF_Db::getTablePrefix() . 'faqdata',
  257. 'id'
  258. );
  259. }
  260. printf(
  261. '<a class="btn btn-success" onclick="addAttachment(\'attachment.php?record_id=%d&amp;record_lang=%s\', \'Attachment\');">%s</a>',
  262. $faqData['id'],
  263. $faqData['lang'],
  264. $PMF_LANG['ad_att_add']
  265. );
  266. ?>
  267. </div>
  268. </div>
  269. <?php endif; ?>
  270. <!-- Tags -->
  271. <div class="control-group">
  272. <label class="control-label" for="tags"><?php echo $PMF_LANG['ad_entry_tags']; ?>:</label>
  273. <div class="controls">
  274. <input type="text" name="tags" id="tags" value="<?php echo $faqData['tags'] ?>"
  275. data-provide="typeahead" data-mode="multiple" />
  276. <span id="tagsHelp" class="hide"><?php echo $PMF_LANG['msgShowHelp']; ?></span>
  277. </div>
  278. </div>
  279. <!-- Keywords -->
  280. <div class="control-group">
  281. <label class="control-label" for="keywords"><?php echo $PMF_LANG["ad_entry_keywords"]; ?></label>
  282. <div class="controls">
  283. <input type="text" name="keywords" id="keywords" maxlength="255"
  284. value="<?php echo $faqData['keywords'] ?>" />
  285. <span id="keywordsHelp" class="hide"><?php echo $PMF_LANG['msgShowHelp']; ?></span>
  286. </div>
  287. </div>
  288. </fieldset>
  289. <fieldset class="form-horizontal">
  290. <?php
  291. if ('00000000000000' == $faqData['dateStart']) {
  292. $faqData['dateStart'] = '';
  293. } else {
  294. $faqData['dateStart'] = preg_replace("/(\d{4})(\d{2})(\d{2}).*/", "$1-$2-$3", $faqData['dateStart']);
  295. }
  296. if ('99991231235959' == $faqData['dateEnd']) {
  297. $faqData['dateEnd'] = '';
  298. } else {
  299. $faqData['dateEnd'] = preg_replace("/(\d{4})(\d{2})(\d{2}).*/", "$1-$2-$3", $faqData['dateEnd']);
  300. }
  301. ?>
  302. <legend><?php echo $PMF_LANG['ad_record_expiration_window']; ?></legend>
  303. <div class="control-group">
  304. <label class="control-label" for="dateStart"><?php echo $PMF_LANG['ad_news_from']; ?></label>
  305. <div class="controls">
  306. <input name="dateStart" id="dateStart" class="date-pick span2" maxlength="10"
  307. value="<?php echo $faqData['dateStart']; ?>" />
  308. </div>
  309. </div>
  310. <div class="control-group">
  311. <label class="control-label" for="dateEnd"><?php echo $PMF_LANG['ad_news_to']; ?></label>
  312. <div class="controls">
  313. <input name="dateEnd" id="dateEnd" class="date-pick span2" maxlength="10"
  314. value="<?php echo $faqData['dateEnd']; ?>" />
  315. </div>
  316. </div>
  317. </fieldset>
  318. <fieldset class="form-horizontal">
  319. <!-- Author -->
  320. <div class="control-group">
  321. <label class="control-label" for="author"><?php echo $PMF_LANG["ad_entry_author"]; ?></label>
  322. <div class="controls">
  323. <input type="text" name="author" id="author" value="<?php echo $faqData['author'] ?>" />
  324. </div>
  325. </div>
  326. <!-- E-Mail -->
  327. <div class="control-group">
  328. <label class="control-label" for="email"><?php echo $PMF_LANG["ad_entry_email"]; ?></label>
  329. <div class="controls">
  330. <input type="email" name="email" id="email" value="<?php echo $faqData['email'] ?>" />
  331. </div>
  332. </div>
  333. </fieldset>
  334. <fieldset class="form-horizontal">
  335. <legend><?php echo $PMF_LANG['ad_entry_changelog']; ?></legend>
  336. <div class="control-group" id="editChangelog">
  337. <label class="control-label"><?php echo $PMF_LANG["ad_entry_date"]; ?></label>
  338. <div class="controls">
  339. <span class="input-medium uneditable-input"><?php echo $faqData['date'] ?></span>
  340. </div>
  341. </div>
  342. <div class="control-group">
  343. <label class="control-label" for="changed"><?php echo $PMF_LANG["ad_entry_changed"]; ?></label>
  344. <div class="controls">
  345. <textarea name="changed" id="changed" class="span8">
  346. <?php echo $faqData['changed'] ?>
  347. </textarea>
  348. </div>
  349. </div>
  350. </fieldset>
  351. <!-- Changelog -->
  352. <?php if (is_numeric($faqData['id'])): ?>
  353. <fieldset>
  354. <legend>
  355. <a href="javascript:void(0);" onclick="javascript:toggleFieldset('editChangelogHistory');">
  356. <?php echo $PMF_LANG['ad_entry_changelog_history']; ?>
  357. </a>
  358. </legend>
  359. <div id="editChangelogHistory" class="hide">
  360. <?php
  361. foreach ($faq->getChangeEntries($faqData['id']) as $entry) {
  362. $user->getUserById($entry['user']);
  363. ?>
  364. <p style="font-size: 10px;">
  365. <label>
  366. <?php printf('%s 1.%d<br/>%s<br/>%s: %s',
  367. $PMF_LANG['ad_entry_revision'],
  368. $entry['revision_id'],
  369. $date->format(date('Y-m-d H:i', $entry['date'])),
  370. $PMF_LANG['ad_entry_author'],
  371. $user->getUserData('display_name')); ?>
  372. </label>
  373. <?php echo $entry['changelog']; ?>
  374. </p>
  375. <?php } ?>
  376. </fieldset>
  377. <?php endif; ?>
  378. </div>
  379. <!-- sidebar -->
  380. <div class="well span3">
  381. <!-- form actions -->
  382. <fieldset>
  383. <div class="control-group">
  384. <label class="control-label" for="dateActualize"><?php echo $PMF_LANG["ad_entry_date"]; ?></label>
  385. <div class="controls">
  386. <label class="radio">
  387. <input type="radio" id="dateActualize" checked="checked" name="recordDateHandling"
  388. onchange="setRecordDate(this.id);" />
  389. <?php echo $PMF_LANG['msgUpdateFaqDate']; ?>
  390. </label>
  391. <label class="radio">
  392. <input type="radio" id="dateKeep" name="recordDateHandling"
  393. onchange="setRecordDate(this.id);" />
  394. <?php echo $PMF_LANG['msgKeepFaqDate']; ?>
  395. </label>
  396. <label class="radio">
  397. <input type="radio" id="dateCustomize" name="recordDateHandling"
  398. onchange="setRecordDate(this.id);" />
  399. <?php echo $PMF_LANG['msgEditFaqDat']; ?>
  400. </label>
  401. </div>
  402. </div>
  403. <div id="recordDateInputContainer" class="control-group hide">
  404. <div class="controls">
  405. <input type="text" name="date" id="date" maxlength="16" value="" />
  406. </div>
  407. </div>
  408. <?php if ($selectedRevisionId == $faqData['revision_id']): ?>
  409. <div class="form-actions">
  410. <button class="btn btn-primary" type="submit">
  411. <?php echo $PMF_LANG["ad_entry_save"]; ?>
  412. </button>
  413. <button class="btn btn-info" type="reset">
  414. <?php echo $PMF_LANG["ad_gen_reset"]; ?>
  415. </button>
  416. </div>
  417. <?php endif; ?>
  418. </fieldset>
  419. <!-- categories -->
  420. <fieldset>
  421. <div class="control-group">
  422. <label class="control-label"><?php echo $PMF_LANG["ad_entry_category"]; ?></label>
  423. <div class="controls">
  424. <select name="rubrik[]" id="rubrik" size="5" multiple="multiple" class="input-medium">
  425. <?php echo $categoryHelper->renderOptions($categories); ?>
  426. </select>
  427. </div>
  428. </div>
  429. </fieldset>
  430. <!-- Activation -->
  431. <fieldset>
  432. <div class="control-group">
  433. <label class="control-label" for="active"><?php echo $PMF_LANG["ad_entry_active"]; ?></label>
  434. <div class="controls">
  435. <?php if($permission['approverec']):
  436. if (isset($faqData['active']) && $faqData['active'] == 'yes') {
  437. $suf = ' checked="checked"';
  438. $sul = null;
  439. } elseif ($faqConfig->get('records.defaultActivation')) {
  440. $suf = ' checked="checked"';
  441. $sul = null;
  442. } else {
  443. $suf = null;
  444. $sul = ' checked="checked"';
  445. }
  446. ?>
  447. <label class="radio">
  448. <input type="radio" id="active" name="active" value="yes"<?php if (isset($suf)) { echo $suf; } ?> />
  449. <?php echo $PMF_LANG['ad_gen_yes']; ?>
  450. </label>
  451. <label class="radio">
  452. <input type="radio" name="active" value="no"<?php if (isset($sul)) { echo $sul; } ?> />
  453. <?php echo $PMF_LANG['ad_gen_no']; ?>
  454. </label>
  455. <?php else: ?>
  456. <label class="radio">
  457. <input type="radio" name="active" value="no" checked="checked" />
  458. <?php echo $PMF_LANG['ad_gen_no']; ?>
  459. </label>
  460. <?php endif; ?>
  461. </div>
  462. </div>
  463. <div class="control-group">
  464. <label class="control-label" for="sticky"><?php echo $PMF_LANG['ad_entry_sticky']; ?>:</label>
  465. <div class="controls">
  466. <label class="checkbox">
  467. <input type="checkbox" id="sticky" name="sticky" <?php echo (isset($faqData['sticky']) && $faqData['sticky'] ? 'checked="checked"' : '') ?> />
  468. &nbsp;
  469. </label>
  470. </div>
  471. </div>
  472. <div class="control-group">
  473. <label class="control-label" for="comment">
  474. <?php echo $PMF_LANG['ad_entry_allowComments']; ?>
  475. </label>
  476. <div class="controls">
  477. <label class="checkbox">
  478. <input type="checkbox" name="comment" id="comment" value="y"<?php echo $faqData['comment'] ?> />
  479. <?php echo $PMF_LANG['ad_gen_yes']; ?>
  480. </label>
  481. </div>
  482. </div>
  483. <?php if ($queryString != 'insertentry'): ?>
  484. <div class="control-group">
  485. <label class="control-label" for="revision">
  486. <?php echo $PMF_LANG['ad_entry_new_revision']; ?>
  487. </label>
  488. <?php
  489. if ($queryString != 'insertentry') {
  490. $rev_yes = ' checked="checked"';
  491. $rev_no = null;
  492. }
  493. if (isset($faqData['active']) && $faqData['active'] == 'no') {
  494. $rev_no = ' checked="checked"';
  495. $rev_yes = null;
  496. }
  497. ?>
  498. <div class="controls">
  499. <label class="radio">
  500. <input type="radio" name="revision" id="revision" value="yes"<?php echo isset($rev_yes) ? $rev_yes : ''; ?>/>
  501. <?php echo $PMF_LANG["ad_gen_yes"]; ?>
  502. </label>
  503. <label class="radio">
  504. <input type="radio" name="revision" value="no"<?php echo isset($rev_no) ? $rev_no : ''; ?>/>
  505. <?php echo $PMF_LANG["ad_gen_no"]; ?>
  506. </label>
  507. </div>
  508. </div>
  509. <?php endif; ?>
  510. <div class="control-group">
  511. <label class="control-label" for="solution_id"><?php echo $PMF_LANG['ad_entry_solution_id']; ?>:</label>
  512. <div class="controls">
  513. <input name="solution_id" id="solution_id" style="width: 50px; text-align: right;" size="5"
  514. readonly="readonly" value="<?php echo (isset($faqData['solution_id']) ? $faqData['solution_id'] : $faq->getSolutionId()); ?>" />
  515. </div>
  516. </div>
  517. </fieldset>
  518. <!-- Permissions -->
  519. <fieldset class="form-inline">
  520. <?php if ($faqConfig->get('security.permLevel') != 'basic'): ?>
  521. <div class="control-group">
  522. <label class="control-label" for="grouppermission"><?php echo $PMF_LANG['ad_entry_grouppermission']; ?></label>
  523. <div class="controls">
  524. <label class="radio">
  525. <input type="radio" id="grouppermission" name="grouppermission" value="all" <?php echo ($allGroups ? 'checked="checked"' : ''); ?>/>
  526. <?php echo $PMF_LANG['ad_entry_all_groups']; ?>
  527. </label>
  528. <label class="radio">
  529. <input type="radio" name="grouppermission" value="restricted" <?php echo ($restrictedGroups ? 'checked="checked"' : ''); ?>/>
  530. <?php echo $PMF_LANG['ad_entry_restricted_groups']; ?>
  531. <select name="restricted_groups" size="1" class="input-medium">
  532. <?php echo $user->perm->getAllGroupsOptions($groupPermission); ?>
  533. </select>
  534. </label>
  535. </div>
  536. </div>
  537. <?php else: ?>
  538. <input type="hidden" name="grouppermission" value="all" />
  539. <?php endif; ?>
  540. <div class="control-group">
  541. <label class="control-label" for="userpermission"><?php echo $PMF_LANG['ad_entry_userpermission']; ?></label>
  542. <div class="controls">
  543. <label class="radio">
  544. <input type="radio" id="userpermission" name="userpermission" value="all" <?php echo ($allUsers ? 'checked="checked"' : ''); ?>/>
  545. <?php echo $PMF_LANG['ad_entry_all_users']; ?>
  546. </label>
  547. <label class="radio">
  548. <input type="radio" name="userpermission" value="restricted" <?php echo ($restrictedUsers ? 'checked="checked"' : ''); ?>/>
  549. <?php echo $PMF_LANG['ad_entry_restricted_users']; ?>
  550. <select name="restricted_users" size="1" class="input-medium">
  551. <?php echo $user->getAllUserOptions($userPermission[0]); ?>
  552. </select>
  553. </label>
  554. </div>
  555. </div>
  556. </fieldset>
  557. </div>
  558. </form>
  559. </div>
  560. <?php
  561. if ($permission["changebtrevs"]) {
  562. $revisions = $faq->getRevisionIds($faqData['id'], $faqData['lang']);
  563. if (count($revisions)) {
  564. ?>
  565. <form id="selectRevision" name="selectRevision" method="post"
  566. action="?action=editentry&amp;id=<?php echo $faqData['id'] ?>&amp;lang=<?php echo $faqData['lang'] ?>">
  567. <fieldset>
  568. <legend><?php echo $PMF_LANG['ad_changerev']; ?></legend>
  569. <p>
  570. <select name="revisionid_selected" onchange="selectRevision.submit();">
  571. <option value="<?php echo $faqData['revision_id']; ?>">
  572. <?php echo $PMF_LANG['ad_changerev']; ?>
  573. </option>
  574. <?php foreach ($revisions as $revisionId => $revisionData) { ?>
  575. <option value="<?php echo $revisionData['revision_id']; ?>" <?php if ($selectedRevisionId == $revisionData['revision_id']) { echo 'selected="selected"'; } ?> >
  576. <?php printf(
  577. '%s 1.%d: %s - %s',
  578. $PMF_LANG['ad_entry_revision'],
  579. $revisionData['revision_id'],
  580. PMF_Date::createIsoDate($revisionData['datum']),
  581. $revisionData['author']
  582. ); ?>
  583. </option>
  584. <?php } ?>
  585. </select>
  586. </p>
  587. </fieldset>
  588. </form>
  589. <?php
  590. }
  591. if (isset($selectedRevisionId) &&
  592. isset($faqData['revision_id']) &&
  593. $selectedRevisionId != $faqData['revision_id']) {
  594. $faq->language = $faqData['lang'];
  595. $faq->getRecord($faqData['id'], $selectedRevisionId, true);
  596. $faqData = $faq->faqRecord;
  597. $faqData['tags'] = implode(',', $tagging->getAllTagsById($faqData['id']));
  598. }
  599. }
  600. ?>
  601. <?php if ($faqConfig->get('main.enableGoogleTranslation') === true): ?>
  602. <fieldset class="form-horizontal">
  603. <legend>
  604. <a href="javascript:void(0);" onclick="javascript:toggleFieldset('Translations');">
  605. <?php echo $PMF_LANG["ad_menu_translations"]; ?>
  606. </a>
  607. </legend>
  608. <div class="control-group hide" id="editTranslations">
  609. <?php
  610. if ($faqConfig->get('main.googleTranslationKey') == '') {
  611. echo $PMF_LANG["msgNoGoogleApiKeyFound"];
  612. } else {
  613. ?>
  614. <label class="control-label" for="langTo"><?php echo $PMF_LANG["ad_entry_locale"]; ?>:</label>
  615. <div class="controls">
  616. <?php echo PMF_Language::selectLanguages($faqData['lang'], false, array(), 'langTo'); ?>
  617. </div>
  618. <input type="hidden" name="used_translated_languages" id="used_translated_languages" value="" />
  619. <div id="getedTranslations">
  620. </div>
  621. <?php
  622. }
  623. ?>
  624. </div>
  625. </fieldset>
  626. <?php endif; ?>
  627. <script type="text/javascript">
  628. /* <![CDATA[ */
  629. function extractor(query) {
  630. var result = /([^,]+)$/.exec(query);
  631. if(result && result[1])
  632. return result[1].trim();
  633. return '';
  634. }
  635. $('#tags').typeahead({
  636. source: function (query, process) {
  637. return $.get("index.php?action=ajax&ajax=tags_list", { q: query }, function (data) {
  638. return process(data.tags);
  639. });
  640. },
  641. updater: function(item) {
  642. return this.$element.val().replace(/[^,]*$/,'')+item+',';
  643. },
  644. matcher: function (item) {
  645. var tquery = extractor(this.query);
  646. if(!tquery) return false;
  647. return ~item.toLowerCase().indexOf(tquery)
  648. },
  649. highlighter: function (item) {
  650. var query = extractor(this.query).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
  651. return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
  652. return '<strong>' + match + '</strong>'
  653. })
  654. }
  655. });
  656. $(function() {
  657. $('.date-pick').datePicker();
  658. $('#date').datePicker({startDate: '1900-01-01'});
  659. $('#date').bind('dateSelected', function (e, date, $td, status)
  660. {
  661. if(status) {
  662. var dt = new Date();
  663. var hours = dt.getHours();
  664. var minutes = dt.getMinutes();
  665. $('#date').val(date.asString() +
  666. ' ' + (hours < 10 ? '0' : '') + hours +
  667. ':' + (minutes < 10 ? '0' : '') + minutes);
  668. }
  669. });
  670. $('#keywords').focus(function() { showHelp('keywords'); });
  671. $('#tags').focus(function() { showHelp('tags'); });
  672. });
  673. /**
  674. * Toggle fieldsets
  675. *
  676. * @param fieldset ID of the fieldset
  677. *
  678. * @return void
  679. */
  680. function toggleFieldset(fieldset) {
  681. if ($('#edit' + fieldset).css('display') == 'none') {
  682. $('#edit' + fieldset).fadeIn('fast');
  683. } else {
  684. $('#edit' + fieldset).fadeOut('fast');
  685. }
  686. }
  687. /**
  688. * Toggle input date container show
  689. *
  690. * @return void
  691. */
  692. function showIDContainer() {
  693. var display = 0 == arguments.length || !!arguments[0] ? 'block' : 'none';
  694. $('#recordDateInputContainer').attr('style', 'display: ' + display);
  695. }
  696. function setRecordDate(how) {
  697. if('dateActualize' == how) {
  698. showIDContainer(false);
  699. $('#date').val('');
  700. } else if ('dateKeep' == how) {
  701. showIDContainer(false);
  702. $('#date').val('<?php echo $faqData['date']; ?>');
  703. } else if('dateCustomize' == how) {
  704. showIDContainer(true);
  705. $('#date').val('');
  706. }
  707. }
  708. /**
  709. * Shows help for keywords and tags input fields
  710. *
  711. * @param option
  712. *
  713. * @return void
  714. */
  715. function showHelp(option) {
  716. $('#' + option + 'Help').fadeIn(500);
  717. $('#' + option + 'Help').fadeOut(2500);
  718. }
  719. /* ]]> */
  720. </script>
  721. <?php
  722. if ($faqConfig->get('main.enableGoogleTranslation') === true) {
  723. ?>
  724. <script src="https://www.google.com/jsapi?key=<?php echo $faqConfig->get('main.googleTranslationKey')?>" type="text/javascript"></script>
  725. <script type="text/javascript">
  726. /* <![CDATA[ */
  727. google.load("language", "1");
  728. var langFromSelect = $("#lang");
  729. var langToSelect = $("#langTo");
  730. // Add a onChange to the faq language select
  731. langFromSelect.change(
  732. function() {
  733. $("#langTo").val($(this).val());
  734. }
  735. );
  736. // Add a onChange to the translation select
  737. langToSelect.change(
  738. function() {
  739. var langTo = $(this).val();
  740. if (! $('#question_translated_' + langTo).val()) {
  741. // Add language value
  742. var languages = $('#used_translated_languages').val();
  743. if (languages == '') {
  744. $('#used_translated_languages').val(langTo);
  745. } else {
  746. $('#used_translated_languages').val(languages + ',' + langTo);
  747. }
  748. var fieldset = $('<fieldset></fieldset>')
  749. .append($('<legend></legend>').html($("#langTo option:selected").text()));
  750. // Text for question
  751. fieldset
  752. .append(
  753. '<div class="control-group">' +
  754. '<label class="control-label" for="question_translated_' + langTo + '">' +
  755. '<?php echo $PMF_LANG["ad_entry_theme"]; ?>' +
  756. '</label>' +
  757. '<div class="controls">' +
  758. '<input type="text" id="question_translated_' + langTo + '" name="question_translated_' + langTo + '" maxlength="255" >' +
  759. '</div>' +
  760. '</div>'
  761. );
  762. // Textarea for answer
  763. fieldset
  764. .append(
  765. '<div class="control-group">' +
  766. '<label class="control-label" for="answer_translated_' + langTo + '">' +
  767. '<?php echo $PMF_LANG["ad_entry_content"]; ?>' +
  768. '</label>' +
  769. '<div class="controls">' +
  770. '<textarea id="answer_translated_' + langTo + '" name="answer_translated_' + langTo + '" cols="80" rows="3" ></textarea>' +
  771. '</div>' +
  772. '</div>'
  773. );
  774. // Textarea for keywords
  775. fieldset
  776. .append(
  777. '<div class="control-group">' +
  778. '<label class="control-label" for="keywords_translated_' + langTo + '">' +
  779. '<?php echo $PMF_LANG["ad_entry_keywords"]; ?>' +
  780. '</label>' +
  781. '<div class="controls">' +
  782. '<textarea id="keywords_translated_' + langTo + '" name="keywords_translated_' + langTo + '" cols="80" rows="3" ></textarea>' +
  783. '</div>' +
  784. '</div>'
  785. );
  786. $('#getedTranslations').append(fieldset);
  787. // Call the init for a new tinyMCE
  788. createTinyMCE('answer_translated_' + langTo);
  789. }
  790. var langFrom = $('#lang').val();
  791. // Set the translated text
  792. getGoogleTranslation('#question_translated_' + langTo, $('#question').val(), langFrom, langTo);
  793. getGoogleTranslation('answer_translated_' + langTo, tinymce.get('answer').getContent(), langFrom, langTo, 'answer');
  794. // Keywords must be translated separately
  795. $('#keywords_translated_' + langTo).val('');
  796. var words = new String($('#keywords').val()).split(',');
  797. for (var i = 0; i < words.length; i++) {
  798. var word = $.trim(words[i]);
  799. getGoogleTranslation('#keywords_translated_' + langTo, word, langFrom, langTo, 'keywords');
  800. }
  801. }
  802. );
  803. /**
  804. * Call the init for a new tinyMCE
  805. *
  806. * @param field id of the input to fill.
  807. *
  808. * @return void
  809. */
  810. function createTinyMCE(field) {
  811. tinyMCE.init({
  812. // General options
  813. mode : "exact",
  814. language : "<?php echo (PMF_Language::isASupportedTinyMCELanguage($LANGCODE) ? $LANGCODE : 'en'); ?>",
  815. elements : field,
  816. width : "720",
  817. height : "480",
  818. theme : "advanced",
  819. plugins : "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,syntaxhl,phpmyfaq",
  820. theme_advanced_blockformats : "p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp",
  821. // Theme options
  822. theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
  823. theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,phpmyfaq,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,syntaxhl,|,insertdate,inserttime,preview,|,forecolor,backcolor",
  824. theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,help",
  825. theme_advanced_toolbar_location : "top",
  826. theme_advanced_toolbar_align : "left",
  827. theme_advanced_statusbar_location : "bottom",
  828. relative_urls : false,
  829. convert_urls : false,
  830. remove_linebreaks : false,
  831. use_native_selects : true,
  832. extended_valid_elements : "code",
  833. // Ajax-based file manager
  834. file_browser_callback : "ajaxfilemanager",
  835. // Example content CSS (should be your site CSS)
  836. content_css : "../assets/template/<?php echo PMF_Template::getTplSetName(); ?>/css/style.css",
  837. // Drop lists for link/image/media/template dialogs
  838. template_external_list_url : "js/template_list.js",
  839. // Replace values for the template plugin
  840. template_replace_values : {
  841. username : "<?php echo $user->userdata->get('display_name'); ?>",
  842. user_id : "<?php echo $user->userdata->get('user_id'); ?>"
  843. }
  844. });
  845. }
  846. /* ]]> */
  847. </script>
  848. <?php
  849. }
  850. } elseif ($permission["editbt"] != 1 && !PMF_Db::checkOnEmptyTable('faqcategories')) {
  851. echo $PMF_LANG["err_NotAuth"];
  852. } elseif ($permission["editbt"] && PMF_Db::checkOnEmptyTable('faqcategories')) {
  853. echo $PMF_LANG["no_cats"];
  854. }