PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/newscoop/admin-files/users/authors.php

https://github.com/nistormihai/Newscoop
PHP | 361 lines | 321 code | 31 blank | 9 comment | 44 complexity | 78c811cb4e42fa94043d2506365e3bcb MD5 | raw file
  1. <?php
  2. /**
  3. * @package Newscoop
  4. */
  5. require_once($GLOBALS['g_campsiteDir'].'/classes/Input.php');
  6. require_once($GLOBALS['g_campsiteDir'].'/classes/Image.php');
  7. require_once($GLOBALS['g_campsiteDir'].'/classes/ImageSearch.php');
  8. require_once($GLOBALS['g_campsiteDir'].'/classes/Log.php');
  9. require_once($GLOBALS['g_campsiteDir'] . "/$ADMIN_DIR/localizer/Localizer.php");
  10. camp_load_translation_strings('users');
  11. camp_load_translation_strings('authors');
  12. // TODO: permissions
  13. if (!is_writable($Campsite['IMAGE_DIRECTORY'])) {
  14. camp_html_add_msg(getGS('Unable to add new image, target directory is not writable.'));
  15. camp_html_add_msg(camp_get_error_message(CAMP_ERROR_WRITE_DIR, $Campsite['IMAGE_DIRECTORY']));
  16. camp_html_goto_page("/$ADMIN/");
  17. exit;
  18. }
  19. if (!$g_user->hasPermission('EditAuthors')) {
  20. camp_html_display_error(getGS('You do not have the permission to change authors.'));
  21. exit;
  22. }
  23. $id = Input::Get('id', 'int', -1);
  24. // Delete author
  25. $del_id = Input::Get('del_id', 'int', -1);
  26. if ($del_id > -1) {
  27. $author = new Author($del_id);
  28. if ($author->delete()) {
  29. camp_html_add_msg(getGS('Author deleted.', 'ok'));
  30. }
  31. }
  32. // Add new author type
  33. $add_author_type = Input::Get('add_author', 'string', null);
  34. if ($add_author_type !== null) {
  35. $authorTypeObj = new AuthorType();
  36. if ($authorTypeObj->create($add_author_type) === true) {
  37. camp_html_add_msg(getGS('Author type added.'), 'ok');
  38. } else {
  39. camp_html_add_msg(getGS('Cannot add author type, this type already exists.'));
  40. }
  41. }
  42. // Delete author type
  43. $del_id_type = Input::Get('del_id_type', 'int', -1);
  44. if ($del_id_type > -1) {
  45. $authorTypeObj = new AuthorType($del_id_type);
  46. if ($authorTypeObj->delete()) {
  47. camp_html_add_msg(getGS('Author type removed.'), 'ok');
  48. } else {
  49. camp_html_add_msg(getGS('Cannot remove author type.'));
  50. }
  51. }
  52. // Delete author alias
  53. $del_id_alias = Input::Get('del_id_alias', 'int', -1);
  54. if ($del_id_alias > -1) {
  55. $authorAliasObj = new AuthorAlias($del_id_alias);
  56. if ($authorAliasObj->delete()) {
  57. camp_html_add_msg(getGS('Author alias removed.'), 'ok');
  58. } else {
  59. camp_html_add_msg(getGS('Cannot remove author alias.'));
  60. }
  61. }
  62. $first_name =Input::Get('first_name');
  63. $last_name = Input::Get('last_name');
  64. $can_save = false;
  65. if ($id > -1 && strlen($first_name) > 0 && strlen($last_name) > 0) {
  66. $can_save = true;
  67. }
  68. if ($can_save) {
  69. $author = new Author();
  70. if ($id > 0) {
  71. $author = new Author($id);
  72. $isNewAuthor = false;
  73. } else {
  74. $author->create(array('first_name' => $first_name, 'last_name' => $last_name));
  75. $isNewAuthor = true;
  76. }
  77. $uploadFileSpecified = isset($_FILES['file'])
  78. && isset($_FILES['file']['name'])
  79. && !empty($_FILES['file']['name']);
  80. $author->setFirstName($first_name);
  81. $author->setLastName($last_name);
  82. $author->commit();
  83. // Reset types
  84. $types = Input::Get('type', 'array', array());
  85. AuthorAssignedType::ResetAuthorAssignedTypes($author->getId());
  86. foreach ($types as $type) {
  87. $author->setType($type);
  88. }
  89. $author->setSkype(Input::Get('skype'));
  90. $author->setJabber(Input::Get('jabber'));
  91. $author->setAim(Input::Get('aim'));
  92. $author->setEmail(Input::Get('email'));
  93. $authorBiography = array();
  94. $authorBiography['biography'] = Input::Get("txt_biography", "string");
  95. $authorBiography['language'] = Input::Get("lang", "int", 0);
  96. $authorBiography['first_name'] = Input::Get("lang_first_name");
  97. $authorBiography['last_name'] = Input::Get("lang_last_name");
  98. $author->setBiography($authorBiography);
  99. if ($uploadFileSpecified) {
  100. $attributes = array();
  101. $image = Image::OnImageUpload($_FILES['file'], $attributes);
  102. if (PEAR::isError($image)) {
  103. camp_html_add_msg($image->getMessage());
  104. } else {
  105. $author->setImage($image->getImageId());
  106. }
  107. }
  108. $aliases = Input::Get("alias", "array");
  109. if (!empty($aliases)) {
  110. $author->setAliases($aliases);
  111. }
  112. if ($isNewAuthor) {
  113. $logtext = getGS('New author "$1" ($2) created.',
  114. $author->getName(), $author->getId());
  115. Log::Message($logtext, $g_user->getUserId(), 172);
  116. } else {
  117. $logtext = getGS('Author information has been changed for "$1" ($2)',
  118. $author->getName(), $author->getId());
  119. Log::Message($logtext, $g_user->getUserId(), 173);
  120. }
  121. camp_html_add_msg(getGS("Author saved."),"ok");
  122. } elseif ($del_id_alias < 1 && $id > -1 && !$can_save) {
  123. camp_html_add_msg(getGS("Please fill at least first name and last name."));
  124. }
  125. if (!$id || $id == -1) {
  126. $author = new Author(1);
  127. if ($id == -1) {
  128. $id = 0;
  129. }
  130. }
  131. $crumbs = array();
  132. $crumbs[] = array(getGS("Configure"), "");
  133. $crumbs[] = array(getGS("Authors"), "");
  134. $breadcrumbs = camp_html_breadcrumbs($crumbs);
  135. echo $breadcrumbs;
  136. ?>
  137. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/js/campsite.js"></script>
  138. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/js/campsite-checkbox.js"></script>
  139. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/js/fValidate/fValidate.config.js"></script>
  140. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/js/fValidate/fValidate.core.js"></script>
  141. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/js/fValidate/fValidate.lang-enUS.js"></script>
  142. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/js/fValidate/fValidate.validators.js"></script>
  143. <script type="text/javascript">
  144. $(document).ready(function(){
  145. $('.filter-button').click(function() {
  146. $('.container').toggle('fast');
  147. $(this).toggleClass("close");
  148. return false;
  149. }).next().hide();
  150. });
  151. </script>
  152. <?php camp_html_display_msgs('1em', '0'); ?>
  153. <div class="wrapper">
  154. <div class="info-bar"> <span class="info-text"></span> </div>
  155. <!--left column-->
  156. <div class="column-one">
  157. <div class="author-list ui-widget-content big-block block-shadow padded-strong">
  158. <fieldset class="plain">
  159. <div class="search-box">
  160. <input type="text" id="form_search" onchange="doSearch()" onkeyup="doSearch()" class="input-transparent" size="45" style="width:220px;" />
  161. <a href="#" class="filter-button"><?php putGS('Filters'); ?></a>
  162. </div>
  163. <div class="container">
  164. <ul class="check-list padded">
  165. <li>
  166. <input type="checkbox" name="all_authors" id="all_authors" class="input_checkbox" checked="checked" onclick="typeFilter(0)" />
  167. <label for="all_authors"><?php putGS('All Author Types'); ?></label>
  168. </li>
  169. <?php
  170. $types = AuthorType::GetAuthorTypes();
  171. foreach ($types as $type) {
  172. echo '<li>
  173. <input type="checkbox" name="One" value="' . $type->getName() . '" id="author_' . $type->getId() . '" class="input_checkbox checkbox_filter" onclick="typeFilter(' . $type->getId() . ')" />
  174. <label for="One">' . $type->getName() . '</label>';
  175. echo '<a href="?del_id_type=' . $type->getId() . '" onclick="return deleteAuthorType(' . $type->getId() . ')" style="float:right"><img
  176. src="' . $Campsite['ADMIN_STYLE_URL'] . '/images/delete.png" border="0" alt="' . getGS('Delete author type') . '" title="' . getGS('Delete author type') . '" /></a>';
  177. echo '</li>';
  178. }
  179. ?>
  180. <li><?php putGS('Add author type'); ?>:</li>
  181. <li>
  182. <form onsubmit="return addAuthorType()" method="post">
  183. <input type="text" style="width: 60%; margin-right: 6px" name="add_author" id="add_author" class="input_text" maxlength="35" />
  184. <input type="submit" class="default-button" value="<?php putGS('Add'); ?>" id="save" name="save" />
  185. </form>
  186. </li>
  187. </ul>
  188. </div>
  189. </fieldset>
  190. <fieldset class="plain" style="margin-top:16px;">
  191. <a onclick="getRow(0)" class="ui-state-default icon-button right-floated" href="#"><span class="ui-icon ui-icon-plusthick"></span><?php putGS('Add new Author'); ?></a>
  192. <div class="clear"></div>
  193. <div id="gridtable" style="margin-top:8px;"></div>
  194. </fieldset>
  195. </div>
  196. </div>
  197. <!--END left column-->
  198. <!--right column-->
  199. <div id="detailtable" class="column-two"><?php putGS('Loading Data'); ?>...</div>
  200. </div>
  201. <script type="text/javascript">
  202. $('.icon-button').hover(
  203. function() { $(this).addClass('ui-state-hover'); },
  204. function() { $(this).removeClass('ui-state-hover'); }
  205. );
  206. $('.text-button').hover(
  207. function() { $(this).addClass('ui-state-hover'); },
  208. function() { $(this).removeClass('ui-state-hover'); }
  209. );
  210. var oTable;
  211. $(document).ready(function() {
  212. $.get('authors_ajax/grid.php',function (data) {
  213. $("#gridtable").html(data);
  214. oTable=$('#gridx').dataTable( {
  215. 'bLengthChange': false,
  216. 'bFilter': true,
  217. 'bJQueryUI':true,
  218. 'aoColumnDefs': [
  219. { // not sortable
  220. 'bSortable': false,
  221. 'aTargets': [1, 2]
  222. }
  223. ],
  224. 'fnDrawCallback': function() {
  225. $('#gridx tbody tr').click(function(event) {
  226. $(event.target).removeClass('selected');
  227. $(event.target).addClass('selected');
  228. });
  229. }
  230. });
  231. $("#gridx_filter").html('');
  232. });
  233. getRow(<?php echo $id; ?>);
  234. });
  235. function addAlias() {
  236. $("#aliases").append('<div class="authorAliasItem"><input type="text" class="input_text authorAlias" name="alias[]" size="41" spellcheck="false" style="width:322px;margin-left:127px"></div>');
  237. }
  238. function addAuthorType() {
  239. var val= $('#add_author').val();
  240. val = jQuery.trim(val);
  241. if (val.length < 3) {
  242. alert("<?php echo putGS("Author type must be at least three characters long.") ?>");
  243. return false;
  244. }
  245. }
  246. function deleteAuthorType(id) {
  247. if (!confirm('<?php echo getGS('Are you sure you want to delete this author type?'); ?>')) {
  248. return false;
  249. }
  250. $.post('?del_id_type=' + id, function(data) {
  251. $.get('authors_ajax/grid.php',function (data) {
  252. $("#gridtable").html(data);
  253. oTable=$('#gridx').dataTable({
  254. "bLengthChange": false,
  255. "bFilter": true,
  256. 'bJQueryUI':true
  257. });
  258. $("#gridx_filter").html('');
  259. });
  260. window.location.replace("?");
  261. });
  262. return false;
  263. }
  264. function deleteAuthorAlias(id, authorId) {
  265. if (!confirm('<?php echo getGS('Are you sure you want to delete this author alias?')?>')) {
  266. return false;
  267. }
  268. $.post('?id=' + authorId + '&del_id_alias=' + id, function(data) {
  269. window.location.replace("?id=" + authorId);
  270. });
  271. }
  272. function deleteAuthor(id) {
  273. if (!confirm('<?php echo getGS('Are you sure you want to delete this author?')?>')) {
  274. return false;
  275. }
  276. $.post('?del_id=' + id, function(data) {
  277. window.location.replace("?");
  278. });
  279. }
  280. function getRow(id) {
  281. $.get('authors_ajax/detail.php?id=' + id, function(data) {
  282. $("#detailtable").html(data);
  283. $(function() {
  284. $(".tabs").tabs({ selected: 0 });
  285. });
  286. });
  287. }
  288. function changeBio(id) {
  289. $.getJSON('authors_ajax/detail.php?id=' + id + '&getBio=1&language=' + $("#lang").val(), function(data) {
  290. $("#txt_biography").html(data.biography);
  291. $("#lang_first_name").val(data.first_name);
  292. $("#lang_last_name").val(data.last_name);
  293. });
  294. }
  295. function changeTranslation(id) {
  296. $.getJSON('authors_ajax/detail.php?id=' + id + '&getBio=1&language=' + $("#lang_trans").val(), function(data) {
  297. $("#transArea").html(data.biography);
  298. });
  299. }
  300. function doSearch() {
  301. oTable.fnFilter( $("#form_search").val(),0);
  302. }
  303. function typeFilter(id) {
  304. if (id == 0 && $("#all_authors").attr('checked')) {
  305. $(".checkbox_filter").removeAttr('checked');
  306. oTable.fnFilter( '',1 );
  307. return;
  308. }
  309. var str="";
  310. var multiple=false;
  311. var is_checked=false;
  312. if (id > 0) {
  313. $("input[type=checkbox][checked][:not('#all_authors')]").not('#all_authors').each(
  314. function() {
  315. is_checked=true;
  316. if (multiple) str = str + "|";
  317. str = str +$("#" + this.id).val();
  318. multiple=true;
  319. }
  320. );
  321. }
  322. if (is_checked) {
  323. $("#all_authors").removeAttr('checked');
  324. } else{
  325. $("#all_authors").attr('checked','checked');
  326. }
  327. oTable.fnFilter(str,1 ,true,true);
  328. }
  329. </script>
  330. <?php camp_html_copyright_notice(); ?>