. // Copyright © 2007-2014 Erwan Briand // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 only. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public // License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . class View { private $ct_session, $ct_db, $page, $error, $langlist, $lang; public $metatags, $maincontent; function __construct($session, $db, $page, $error, $langlist, $lang) { // Variables $this->ct_session = $session; $this->ct_db = $db; $this->page = $page; $this->error = $error; $this->langlist = $langlist; $this->lang = $lang; // Meta tags $title = i18n('Validation - Projects - Administration'); $this->metatags = array('title' => $title); // Only admins verify_user_level($_SESSION['id'], 'administrator', $this->ct_session, $this->error, $this->ct_db); $this->projects = getClass('projects.projects', $this->ct_db); if (!empty($this->page[4]) && !empty($this->page[5]) && in_array($this->page[4], array('delete', 'approval')) && is_numeric($this->page[5])) { $project = $this->projects->load($this->page[5]); if (!$project) $this->error->displayError(i18n('Project not found.'), 0); $userid = $this->projects->getUserid(); $dbname = $this->projects->getDbname(); $scm = $this->projects->getSCM(); $user = getUser($userid, $this->ct_db); if ($this->page[4] == 'approval') { if (!empty($_SERVER['HTTP_REFERER']) && CT_BASEURL. 'admin/projects/validate' != $_SERVER['HTTP_REFERER']) exit('Error.'); $this->projects->updateField('is_valid', TRUE); $this->svnadmin = getClass('project.scmadmin', array($scm, strtolower($dbname))); if ($this->svnadmin->createRepository()) { $this->svnadmin->addUser($user->getNickname(), $user->getApache_password()); $this->svnadmin->togglePrivate($this->projects->getPrivacy()); } $pname = $this->projects->getName(); $user = getUser($userid, $this->ct_db); $uname = $user->getNickname(); $to = $user->getEmail(); // Change locale settings setlocale(LC_ALL, $user->getLang().'.UTF-8'); $subject = i18n('%(prj)s has been approved!', array('prj' => $pname)); $text = i18n("Hi, %(u)s.\n\n". "Your project %(prj)s has been approved.\n", array('prj' => $pname, 'u' => $uname)). CT_BASEURL."project/".$dbname; sendmail($subject, $text, $to, $this->ct_db); // Restore local settings setlocale(LC_ALL, $this->lang.'.UTF-8'); } Header('Location: '.CT_BASEURL.'admin/projects/validate'); } } function treatForms() { return TRUE; } function constructView() { $construct = array(); $construct['__tpl__'] = 'admin-validate.tpl'; $list = $this->projects->listProjects(array('is_valid' => FALSE), 'id DESC'); if (!$list) $construct['projects_waiting'] = FALSE; else { $construct['projects_waiting'] = TRUE; $construct['projects'] = array(); foreach ($list as $prj) { $user = getUser($prj['userid'], $this->ct_db); array_push($construct['projects'], array('name' => htmlspecialchars($prj['name']), 'dbname' => htmlspecialchars($prj['dbname']), 'website' => htmlspecialchars($prj['website']), 'nick' => htmlspecialchars($user->getNickname()), 'date' => i18nDate($prj['date'], $this->lang), 'id' => $prj['id'])); } } return $construct; } } ?>