<?php
class admin extends website {
public function __construct( $key ) {
parent::__construct($key );
$this->keyContent = 'general';
if (isset($_GET['k']))
$this->keyContent = $_GET['k'];
}
public function display() {
$this->setContent();
include('templates/default/admin.html');
}
public function getMenu() {
$array = array(
'general' => 'Infos générales',
'informations' => 'Première page',
'users' => 'Utilisateurs',
'photos' => 'Photos',
'calendar' => 'Calendrier'
);
if ( isset ( $this->options['meteo'] ) ) $array = array_merge ( $array , array( 'meteo' => 'Météo' ) );
if ( isset ( $this->options['map'] ) ) $array = array_merge ( $array , array( 'map' => 'Adresse' ) ) ;
$content = '<div id="top-menu">
<ul>';
$width = (748-2*count($array))/count($array);
foreach ( $array as $key => $title ) {
$class = ($key == $this->keyContent )? 'class="act"': '';
$content .= '<li style="width:'.$width.'px;border-right:2px solid #FFFFFF" ><a "'.$class.'" href="admin-'. $key .'.html" title="informations">'. $title .'</a></li>';
}
$content .= '</ul></div>';
return $content;
}
public function setContent() {
if ( $this->keyContent == 'general' ) {
$content .= $this->getAdminGeneral();
} else if ( $this->keyContent == 'informations' ){
$content .= $this->getAdminInformations();
} else if ( $this->keyContent == 'users' ) {
$content .= $this->getAdminUsers();
} else if ( $this->keyContent == 'calendar' ) {
$content .= $this->getAdminCalendar();
} else if ( $this->keyContent == 'photos' ) {
$content .= $this->getAdminPhotos();
} else if ( $this->keyContent == 'meteo' ) {
$content .= $this->getAdminMeteo();
} else if ( $this->keyContent == 'map' ) {
$content .= $this->getAdminMap();
} else {
$content .= 'Une erreur est survenue... ';
}
$content .= '';
$this->content = $content;
}
public function getAdminInformations() {
if (isset($_POST['id']))
$this->saveContent($_POST['html']);
$content = '<form id="add-event" action="'.$_SERVER['REQUEST_URI'].'" method="post">';
$content .= '<textarea class="jquery_ckeditor" cols="80" id="editor1" name="html" rows="10">'. stripslashes($this->options['informations']['html']) .'</textarea>';
$content .= '<input type="hidden" name="id" value="'. $this->options['informations']['id'] .'" />';
$content .= '<input type="submit" name="submit" value="Valider" /></form>';
return $content;
}
public function getAdminMeteo() {
if (isset($_POST['id']))
$this->saveContent($_POST['html']);
$content = '<form id="add-event" action="'.$_SERVER['REQUEST_URI'].'" method="post">';
$content .= 'Localité : <input typ="text" name="html" value="'. stripslashes($this->options['meteo']['html']) .'" />';
$content .= '<input type="hidden" name="id" value="'. $this->options['meteo']['id'] .'" />';
$content .= '<input type="submit" name="submit" value="Valider" /></form>';
return $content;
}
public function getAdminMap() {
if (isset($_POST['id'])) {
$this->saveContent( serialize ( array ( 'address' => $_POST['address'], 'info' => $_POST['info'] )));
}
$v = unserialize (stripslashes($this->options['map']['html'] ) );
$content = '<form id="add-event" action="'.$_SERVER['REQUEST_URI'].'" method="post">';
$content .= 'Adresse : <input typ="text" name="address" value="'. $v['address'] .'" /><br />';
$content .= 'Informations complémentaires : <input typ="text" name="info" value="'. $v['info'] .'" /><br />';
$content .= '<input type="hidden" name="id" value="'. $this->options['map']['id'] .'" />';
$content .= '<input type="submit" name="submit" value="Valider" /></form>';
return $content;
}
public function getAdminGeneral() {
$content = '';
$this->headCode .= '<link rel="stylesheet" href="templates/default/css/admin/farbtastic.css" type="text/css" />
<script type="text/javascript" src="templates/default/js/admin/farbtastic.js"></script>
<script type="text/javascript" >
$(document).ready(function() {
$("#picker").farbtastic("#color");
});
</script>';
if (isset($_POST['footer'])) {
$this->footer = $_POST['footer'];
}
if (isset($_POST['color'])) {
$this->color = substr( $_POST['color'], -6 );
}
if ( isset( $_FILES['img_header'] ) ) {
$u = new upload();
$u->upload_file( 'img_header', 'uploads/'.$this->key .'/', 'image' );
$element->question_number = $_POST['q'];
if ($u->error == 'sucess') {
$this->img_header = $u->filename;
}
else {
$content .= $u->error;
}
}
if (isset($_POST)) {
$this->save();
}
$content .= '<form action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data" method="post">';
$content .= '<h1>Couleur de fond</h1><div class="form-item"><label for="color">Couleur : </label><input type="text" id="color" name="color" value="#'. $this->color .'" /></div><div id="picker"></div>';
$content .= '<br /><br /><h1>Image principale</h1>L\'image principale est celle affichée en haut de toutes les pages. Celle ci est donc très importante.<br />
Nous vous conseillons de la choisir beaucoup plus large que haute pour une meilleure ergonomie.<br />
<label >image : </label><img src="uploads/'.$this->key .'/'. $this->img_header .'" width="100" /><br/><input type="file" name="img_header" />';
$content .= '<br /><br /><h1>Note en pied de page</h1><label >Texte : </label><input type="text" name="footer" value="'. stripslashes($this->footer) .'" />';
$content .= '<br /><br /><input type="submit" name="submit" value="Valider" /></form>';
return $content;
}
public function getAdminUsers() {
if (isset($_POST['email']))
$this->saveUser();
$content = '';
$q = db::getInstance()->q( 'SELECT *, sm_jtusers.status as type FROM `sm_jtusers` , `sm_users`
WHERE `FK_web_id` = "'. $this->id .'" AND FK_use_id = id ');
$content .= '<table style="width : 100%" >';
$content .= '<tr style="background:#dddddd" ><td>Email</td><td>Nom</td><td>Prénom</td><td>Administrateur</td></tr>';
while ( $array = $q->fetch_array() ) {
$content .= '<tr><td>'.$array['email'].'</td><td>'.$array['name'].'</td><td>'.$array['surname'].'</td><td>'.$array['type'].'</td></tr>';
}
$content .= '</table><br /><br />
<h1>Ajouter un utilisateur</h1>
<form id="add-user" action="'.$_SERVER['REQUEST_URI'].'" method="post"><table>';
$content .= '<tr><td>Type :</td>
<td><input type="radio" name="type" value="1" checked />Normal '.help::picto('Mode normal: permet uniquement à l\'utilisateur de voir le site (sans ajout de photos, ni d\'événements dans le calendrier)').'
<input type="radio" name="type" value="2" />Contributeur '.help::picto('Mode contributeur: permet à l\'utilisateur de voir le site, ajouter de photos, et des événements dans le calendrier').'
<input type="radio" name="type" value="3" />Administrateur '.help::picto('Mode administrateur: l\'utilisateur posséde tous les droits: ajout de nouveaux utilisateurs, suppression de photos et d\'événements...').' </td></tr>
<tr><td>Email :</td><td><input type="text" name="email" value="" /></td></tr>
<tr><td align="left" ><input type="checkbox" checked name="confirmemail" value="1" /></td><td>Envoi de l\'email de présentation</td></tr>';
$content .= '<tr><td colspan="2"><input type="submit" name="submit" value="Valider" /></td></tr>
</table></form>';
return $content;
}
public function saveContent( $html ) {
$option = new option( $_POST['id']);
$option->html = $html;
$option->save();
$this->set_options();
}
public function saveUser() {
$chaine = "abcdefghijklmnopqrstuvwxyz123456789";
$nb_caract = 6;
$pass = '';
for($u = 1; $u <= $nb_caract; $u++) {
$nb = strlen($chaine);
$nb = mt_rand(0,($nb-1));
$pass .= $chaine[$nb];
}
$user = user::getUserByEmail( $_POST['email']);
if ( !isset( $user->id ) ) { $user->pass = $pass; }
$user->save();
$user->addWebsite( $this->id, $_POST['type']);
if ( isset( $_POST['confirmemail'] ) ) {
$this->sendConfirm($user->email , $user->pass);
}
}
public function sendConfirm($email,$pass) {
$mail = new email();
$mail -> addrecipient($email);
$mail -> addfrom(user::get_session()->email,user::get_session()->name.' '.user::get_session()->surname);
$mail -> addsubject('Bienvenue sur '.$this->url);
$mail -> html = 'Bonjour<br />Un nouveau site est en ligne!<br/><b><a href="'. $this->url .'">'. $this->url .'</a></b><br/>Vous êtes invité à le découvrir avec les identifiants suivants:<br >Email : '. $email .'<br/>Mot de passe : '.$pass .
'<br/><br/>Tout l\'équipe de site-maison.fr vous souhaite la bienvenue.';
$mail -> sendmail();
}
public function getAdminPhotos () {
$content .= photo::uploadForm();
$this->headCode .= photo::displayAllHeadCode();
$content .= photo::displayAll( true );
return $content;
}
public function getAdminCalendar () {
echo 'a';
$content .= calendar::displayAll (true);
echo 'b';
return $content;
}
}
?>