add('NewsAdmin', l10n('title_admin_news'), $my_base_url.'&tab=NewsAdmin'); $tabsheet->add('Users', l10n('title_users'), $my_base_url.'&tab=Users'); $tabsheet->add('Groups', l10n('title_groups'), $my_base_url.'&tab=Groups'); $tabsheet->add('Config', l10n('config'), $my_base_url.'&tab=Config'); $tabsheet->select($page['tab']); $tabsheet->assign(); $page['NewsAdmin'] = array(); $error = array(); // +-----------------------------------------------------------------------+ // | Tabssheet select | // +-----------------------------------------------------------------------+ switch ($page['tab']) { // ************************************************************************* // +-----------------------------------------------------------------------+ // | NewsAdmin | // +-----------------------------------------------------------------------+ // ************************************************************************* case 'NewsAdmin': $page_news_admin = get_admin_plugin_menu_link(dirname(__FILE__).'/news_admin.php'); // detection of the start news to display if ( !isset( $_GET['start'] ) or !is_numeric( $_GET['start'] ) or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) { $page['start'] = 0; } else { $page['start'] = $_GET['start']; } // detection of the number of news to display per page if ( !isset( $_GET['nb_news_page'] ) or !is_numeric( $_GET['nb_news_page'] ) or ( is_numeric( $_GET['nb_news_page'] ) and $_GET['nb_news_page'] < 0 ) ) { $page['nb_news_page'] = $conf['nb_news_page']; } else { $page['nb_news_page'] = $_GET['nb_news_page']; } // +-----------------------------------------------------------------------+ // | news management | // +-----------------------------------------------------------------------+ // // GET // //delete a translation if ( isset($_GET['action']) and ($_GET['action']=='delt') and isset($_GET['idt']) and is_numeric($_GET['idt']) and !is_adviser() ) { //get new_id $query = ' SELECT new_id FROM '.NEWS_TRANSLATION_TABLE.' WHERE id = \''.$_GET['idt'].'\' ;'; $result = pwg_query($query); $row = mysql_fetch_array($result); $new_id=$row['new_id']; //delete news_translation $query = ' DELETE FROM '.NEWS_TRANSLATION_TABLE.' WHERE id = \''.$_GET['idt'].'\' ;'; pwg_query($query); //get others translations of the news $query = ' SELECT id FROM '.NEWS_TRANSLATION_TABLE.' WHERE new_id = \''.$new_id.'\' ;'; $result = pwg_query($query); //if there is no others translations, delete the news if (mysql_num_rows ($result) <= 0) { $query = ' DELETE FROM '.NEWS_TABLE.' WHERE id = \''.$new_id.'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_TRANSLATION_TABLE.' WHERE new_id = \''.$new_id.'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_GROUP_ACCESS_TABLE.' WHERE new_id = \''.$new_id.'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_USER_ACCESS_TABLE.' WHERE new_id = \''.$new_id.'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_GROUP_REFUSED_TABLE.' WHERE new_id = \''.$new_id.'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_USER_REFUSED_TABLE.' WHERE new_id = \''.$new_id.'\' ;'; pwg_query($query); // information message array_push($page['infos'], $lang['news_deleted']); } else { // information message array_push($page['infos'], $lang['translation_deleted']); } } //delete a news else if ( isset($_GET['action']) and ($_GET['action']=='deln') and isset($_GET['idn']) and is_numeric($_GET['idn']) and !is_adviser() ) { $query = ' DELETE FROM '.NEWS_TABLE.' WHERE id = \''.$_GET['idn'].'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_TRANSLATION_TABLE.' WHERE new_id = \''.$_GET['idn'].'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_GROUP_ACCESS_TABLE.' WHERE new_id = \''.$_GET['idn'].'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_USER_ACCESS_TABLE.' WHERE new_id = \''.$_GET['idn'].'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_GROUP_REFUSED_TABLE.' WHERE new_id = \''.$_GET['idn'].'\' ;'; pwg_query($query); $query = ' DELETE FROM '.NEWS_USER_REFUSED_TABLE.' WHERE new_id = \''.$_GET['idn'].'\' ;'; pwg_query($query); // information message array_push($page['infos'], $lang['news_deleted']); } // // POST // //add translation if (isset($_POST['addt']) and isset( $_POST['content'] ) and !empty($_POST['content']) and !is_adviser() ) { $message=$_POST['content']; $query = ' INSERT INTO '.NEWS_TRANSLATION_TABLE.' (new_id, language, title, content) VALUES ( '.$_POST['idn'].', \''.$_POST['language'].'\', \''.$_POST['title'].'\', \''.$message.'\' );'; pwg_query( $query ); // information message array_push($page['infos'], $lang['translation_added']); } //mod translation else if (isset($_POST['modt']) and isset( $_POST['content'] ) and !empty($_POST['content']) and !is_adviser() ) { $message=$_POST['content']; $query = ' UPDATE '.NEWS_TRANSLATION_TABLE.' SET language=\''.$_POST['language'].'\', title=\''.$_POST['title'].'\', content=\''.$message.'\' WHERE id=\''.$_POST['idt'].'\' ;'; pwg_query( $query ); // information message array_push($page['infos'], $lang['translation_altered']); } //add news else if (isset($_POST['addn']) and isset( $_POST['content'] ) and !empty($_POST['content']) and !is_adviser() ) { $message=$_POST['content']; $query = ' INSERT INTO '.NEWS_TABLE.' (date, author) VALUES ( NOW(), \''.$_POST['author'].'\' );'; pwg_query( $query ); $query = ' INSERT INTO '.NEWS_TRANSLATION_TABLE.' (new_id, language, title, content) VALUES ( LAST_INSERT_ID(), \''.$_POST['language'].'\', \''.$_POST['title'].'\', \''.$message.'\' );'; pwg_query( $query ); // \''.htmlspecialchars($_POST['title'], ENT_QUOTES).'\', // information message array_push($page['infos'], $lang['news_added']); $page['start']=0; } else if (isset($_POST['change_status_submit']) and isset($_POST['idn']) and !is_adviser() ) { $query = ' SELECT * FROM '.NEWS_TABLE.' WHERE id=\''.$_POST['idn'].'\' ;'; $result = pwg_query($query); $row = mysql_fetch_array($result); $status = ($row['status']=='private')?'public':'private'; $query = ' UPDATE '.NEWS_TABLE.' SET status=\''.$status.'\' WHERE id=\''.$_POST['idn'].'\' ;'; pwg_query( $query ); // information message array_push($page['infos'], $lang['news_status_changed'].$lang[$status]); } // +-----------------------------------------------------------------------+ // | page header and options | // +-----------------------------------------------------------------------+ $template->assign( array( 'F_ACTION' => add_url_params($page_news_admin, array()), 'U_POST_NEWS' => add_url_params($page_news_admin, array('action' => 'addn')), /*'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=news_admin',*/ 'U_NEWS' => add_url_params($page_news_admin, array( 'nb_news_page' => $page['nb_news_page'], 'start' => $page['start'], ) ), ) ); // +-----------------------------------------------------------------------+ // | DISPLAY FORMS | // +-----------------------------------------------------------------------+ // //display form to add news // if (isset($_GET['action']) and $_GET['action']=='addn') { //donne le titre ajouter une news dans h2 $template->assign('new_news',array()); //get every languages $available_lang=get_languages(); $lang_select=news_language_select($available_lang,$user['language']); $template->assign( 'form', array( 'AUTHOR'=>$user['username'], 'LANG_SELECT'=>$lang_select, 'SUBMIT_NAME' =>'addn' ) ); } // //display form to add a translation // else if (isset($_GET['action']) and $_GET['action']=='addt' and isset($_GET['idn']) and is_numeric($_GET['idn']) ) { //donne le titre ajouter une news dans h2 $template->assign('news_translation',array()); //get every languages $available_lang=get_languages(); $not_translated_languages=$available_lang; //display author and date $query = ' SELECT DISTINCT(id) AS new_id, date, author FROM '.NEWS_TABLE.' WHERE id=\''.$_GET['idn'].'\' ;'; $result = pwg_query($query); $row = mysql_fetch_array($result); $template->assign( 'news', array( 'NEWS_AUTHOR'=>$row['author'], 'NEWS_DATE'=>format_date($row['date'],'mysql_datetime',true), ) ); //display the news translations $query = ' SELECT id AS news_translation_id,language,title,content FROM '.NEWS_TRANSLATION_TABLE.' WHERE new_id = \''.$_GET['idn'].'\' ;'; $subresult = pwg_query($query); while ($subrow = mysql_fetch_array($subresult)) { //ready for bbcode $message=preg_replace('/\:[0-9a-z\:]+\]/si', ']', $subrow['content']); $message = str_replace("\n", "\n
\n", $message); $template->assign( 'news.news_translation', array( 'TITLE'=>$subrow['title'], 'CONTENT'=>$message, 'LANG_TITLE' => ucwords($available_lang[$subrow['language']]), ) ); //delete language from not translated languages table $keys_indexes=array_flip(array_keys($not_translated_languages)); array_splice ($not_translated_languages, $keys_indexes[$subrow['language']],1); } $lang_select=news_language_select($not_translated_languages,$user['language']); $template->assign( 'form', array( 'new_id'=>$_GET['idn'], 'LANG_SELECT'=>$lang_select, 'SUBMIT_NAME' =>'addt' ) ); } // //display form to alter a translation // else if (isset($_GET['action']) and $_GET['action']=='modt' and isset($_GET['idt']) and is_numeric($_GET['idt'])) { //donne le titre edit news dans h2 $template->assign('title_edit_news',array()); //get every languages $available_lang=get_languages(); $not_translated_languages=$available_lang; //get the news translation $query = ' SELECT id AS news_translation_id,language,title,content,new_id FROM '.NEWS_TRANSLATION_TABLE.' WHERE id = \''.$_GET['idt'].'\' ;'; $result = pwg_query($query); $row = mysql_fetch_array($result); // //display author and date // $query = ' SELECT DISTINCT(id) AS new_id, date, author FROM '.NEWS_TABLE.' WHERE id=\''.$row['new_id'].'\' ;'; $subresult = pwg_query($query); $subrow = mysql_fetch_array($subresult); // //display the news translations // $query = ' SELECT id AS news_translation_id,language,title,content FROM '.NEWS_TRANSLATION_TABLE.' WHERE new_id = \''.$row['new_id'].'\' AND id!=\''.$_GET['idt'].'\' ;'; while ($subrow = mysql_fetch_array($subresult)) { //if ($_GET['idt']!=$subrow['news_translation_id']) //{ $message=preg_replace('/\:[0-9a-z\:]+\]/si', ']', $subrow['content']); $message = str_replace("\n", "\n
\n", $message); $template->assign( 'news.news_translation', array( 'TITLE'=>$subrow['title'], 'CONTENT'=>$message, 'LANG_TITLE' => ucwords($available_lang[$subrow['language']]), ) ); //delete language from not translated languages table $keys_indexes=array_flip(array_keys($not_translated_languages)); array_splice ($not_translated_languages, $keys_indexes[$subrow['language']],1); } $query = ' SELECT * FROM '.NEWS_TRANSLATION_TABLE.' WHERE id = \''.$_GET['idt'].'\' ;'; $category = mysql_fetch_array( pwg_query( $query ) ); $form_action = add_url_params($page_news_admin, array('new_id' => $_GET['idt'])); //get every languages $lang_select=news_language_select($not_translated_languages,$row['language']); $message=preg_replace('/\:[0-9a-z\:]+\]/si', ']', $row['content']); $template->assign( 'form', array( 'NEWS_TRANSLATION_ID'=>$_GET['idt'], 'LANG_SELECT'=>$lang_select, 'TITLE'=> $row['title'], 'CONTENT'=> $message, 'SUBMIT_NAME' =>'modt', ) ); } // // display news // else { $template->assign('adminnews',array()); // +-----------------------------------------------------------------------+ // | news per pages & nav bar display | // +-----------------------------------------------------------------------+ //get number of news // Nombre de news $query = ' SELECT COUNT(DISTINCT(id)) as nb_news FROM '.NEWS_TABLE.' ;'; $result = pwg_query($query); $row = mysql_fetch_array($result); $page['nb_news']=$row['nb_news']; //display number of news per page link $template->assign('adminnews.news_per_page',array()); foreach ($conf['nb_news_page_option'] as $option) { $template->assign( 'adminnews.news_per_page.nb_option', array( 'OPTION' => $option, 'T_STYLE' => ($option == $page['nb_news_page'])?'text-decoration:underline;':'', 'U_OPTION' => add_url_params($page_news_admin, array('nb_news_page' => $option)), ) ); } //display nav bar $page['navigation_bar'] = create_navigation_bar( add_url_params($page_news_admin, array('nb_news_page' => $page['nb_news_page'])), $page['nb_news'],$page['start'],$page['nb_news_page'], false ); $template->assign( 'adminnews.navigation', array( 'NAV_BAR' => $page['navigation_bar'] ) ); // +-----------------------------------------------------------------------+ // | last news display | // +-----------------------------------------------------------------------+ //get every languages $available_lang=get_languages(); $query = ' SELECT DISTINCT(id) AS new_id, date, author, status FROM '.NEWS_TABLE.' ORDER BY date DESC LIMIT '.$page['start'].','.$page['nb_news_page'].' ;'; $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { $new_id = $row['new_id']; $template->assign( 'news', array( 'NEWS_AUTHOR' => $row['author'], 'NEWS_DATE' => format_date($row['date'],'mysql_datetime',true), 'STATUS_NEWS' => $lang[$row['status']], 'NEW_ID' => $row['new_id'], 'U_NEWS_DELETE' => add_url_params($page_news_admin, array( 'action' => 'deln', 'idn' => $row['new_id'], )), ) ); //get the news translation $query = ' SELECT id AS news_translation_id,language,title,content FROM '.NEWS_TRANSLATION_TABLE.' WHERE new_id = \''.$new_id.'\' '; $no_news_translation = false; //get every translations $subresult = pwg_query($query); $not_translated_languages=$available_lang; //show every translation while ($subrow = mysql_fetch_array($subresult)) { $message=$subrow['content']; $template->assign( 'news.news_translation', array( 'TITLE'=>$subrow['title'], 'CONTENT'=>$message, 'LANG_TITLE' => ucwords($subrow['language']), 'U_MODIFY' => add_url_params($page_news_admin, array( 'action' => 'modt', 'idt' => $subrow['news_translation_id'], )), 'U_DELETE' => add_url_params($page_news_admin, array( 'action' => 'delt', 'idt' => $subrow['news_translation_id'], )), ) ); //delete language from not translated languages table //$keys_indexes=array_flip(array_keys($not_translated_languages)); //array_splice ($not_translated_languages, $keys_indexes[$subrow['language']],1); } //news not translated in every languages if (count($not_translated_languages) > 0) { $template->assign( 'news.translate', array( 'ICONPATH' => NBC_NEWS_PATH . 'template/icon', 'U_TRANSLATE' => add_url_params($page_news_admin, array( 'action' => 'addt', 'idn' => $new_id, )), ) ); } if ($row['status'] == 'private') { $template->assign( 'news.perm', array( 'U_PERM' => add_url_params(get_admin_plugin_menu_link(dirname(__FILE__).'/news_perm.php'), array('new_id' => $new_id)), ) ); } } } // +-----------------------------------------------------------------------+ // | errors display | // +-----------------------------------------------------------------------+ if (isset ($errors) and count($errors) != 0) { $template->assign('errors',array()); foreach ($errors as $error) { array_push($page['errors'], $error); } } // +-----------------------------------------------------------------------+ // | templates display | // +-----------------------------------------------------------------------+ $template->set_filenames(array('news' => dirname(__FILE__) . '/template/news_admin.tpl')); //$template->set_filename('news', dirname(__FILE__) . '/template/news_admin.tpl'); $template->assign_var_from_handle('ADMIN_CONTENT', 'news'); break; // ************************************************************************* // +-----------------------------------------------------------------------+ // | Users | // +-----------------------------------------------------------------------+ // ************************************************************************* case 'Users': $query = ' SELECT id, username FROM '.USERS_TABLE.' ORDER BY username ASC ;'; $result = pwg_query($query); $num = 0; while ($row = mysql_fetch_array($result)) { $template->assign( 'user', array( 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', 'NAME' => $row['username'], 'U_PERM' => add_url_params(get_admin_plugin_menu_link(dirname(__FILE__).'/news_user_perm.php'), array('user_id' => $row['id'])), ) ); } $template->assign( array( 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=news_users', ) ); $template->set_filenames(array('news_user_list' => NBC_NEWS_PATH.'template/admin/news_user_list.tpl')); $template->assign_var_from_handle('ADMIN_CONTENT', 'news_user_list'); break; // ************************************************************************* // +-----------------------------------------------------------------------+ // | Groups | // +-----------------------------------------------------------------------+ // ************************************************************************* case 'Groups': $template->set_filenames(array('news_group_list' => NBC_NEWS_PATH . 'template/admin/news_group_list.tpl')); $query = ' SELECT id, name FROM '.GROUPS_TABLE.' ORDER BY name ASC ;'; $result = pwg_query($query); $num = 0; while ($row = mysql_fetch_array($result)) { $query = ' SELECT COUNT(*) FROM '.USER_GROUP_TABLE.' WHERE group_id = '.$row['id'].' ;'; list($counter) = mysql_fetch_row(pwg_query($query)); $template->assign( 'group', array( 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', 'NAME' => $row['name'], 'MEMBERS' => sprintf(l10n('%d members'), $counter), 'U_MEMBERS' => PHPWG_ROOT_PATH.'admin.php?page=user_list&group='.$row['id'], 'U_PERM' => add_url_params(get_admin_plugin_menu_link(dirname(__FILE__).'/news_group_perm.php'), array('group_id' => $row['id'])), ) ); } $template->assign( array( 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=news_groups', ) ); $template->assign_var_from_handle('ADMIN_CONTENT', 'news_group_list'); break; // ************************************************************************* // +-----------------------------------------------------------------------+ // | Users | // +-----------------------------------------------------------------------+ // ************************************************************************* case 'Config': $template->set_filenames(array('news_config' => NBC_NEWS_PATH . 'template/admin/news_config.tpl')); $conf_nbc_News = explode(";" , $conf['nbc_News']); if ( isset($_POST['submit']) and !is_adviser() ) { $conf_nbc_News = array( str_replace("\'", "'", $_POST['nb_homepage']), str_replace("\'", "'", $_POST['nb_page']), str_replace("\'", "'", $_POST['nb_page_option']), ); $newconf_nbc_News = implode (";" , $conf_nbc_News); $query = ' UPDATE '.CONFIG_TABLE.' SET value="'.$newconf_nbc_News.'" WHERE param="nbc_News" LIMIT 1'; pwg_query($query); // information message array_push($page['infos'], $lang['nbc_news_save_config']); } $template->assign( array( //'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=news_config', 'NBC_News_F_ACTION' => add_url_params($page_news_admin, array('tab' => 'Config')), 'nb_homepage_CONTENT' => $conf_nbc_News[0], 'nb_page_CONTENT' => $conf_nbc_News[1], 'nb_page_option_CONTENT' => $conf_nbc_News[2], ) ); $template->assign_var_from_handle('ADMIN_CONTENT', 'news_config'); break; } ?>