* it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Goteo 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 Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>. * */ use Goteo\Library\Text, Goteo\Library\i18n\Lang; $project = $this['project']; $langs = Lang::getAll(); $filters = $this['filters']; ?> <script type="text/javascript"> function assign() { if (document.getElementById('assign-user').value != '') { document.getElementById('form-assign').submit(); return true; } else { alert('No has seleccionado ningun traductor'); return false; } } </script> <div class="widget"> <?php
public static function process($action = 'list', $id = null, $filters = array(), $subaction = '') { // @NODESYS $nodes = array(); // @NODESYS $node = \GOTEO_NODE; $errors = array(); switch ($action) { case 'add': // si llega post: creamos if ($_SERVER['REQUEST_METHOD'] == 'POST') { // para crear se usa el mismo método save del modelo, hay que montar el objeto $user = new Model\User(); $user->userid = $_POST['userid']; $user->name = $_POST['name']; $user->email = $_POST['email']; $user->password = $_POST['password']; $user->node = !empty($_POST['node']) ? $_POST['node'] : \GOTEO_NODE; if (isset($_SESSION['admin_node']) && $user->node != $_SESSION['admin_node']) { $user->node = $_SESSION['admin_node']; } $user->save($errors); if (empty($errors)) { // mensaje de ok y volvemos a la lista de usuarios Message::Info(Text::get('user-register-success')); throw new Redirection('/admin/users/manage/' . $user->id); } else { // si hay algun error volvemos a poner los datos en el formulario $data = $_POST; Message::Error(implode('<br />', $errors)); } } // vista de crear usuario return new View('view/admin/index.html.php', array('folder' => 'users', 'file' => 'add', 'data' => $data, 'nodes' => $nodes)); break; case 'edit': $user = Model\User::get($id); // si llega post: actualizamos if ($_SERVER['REQUEST_METHOD'] == 'POST') { $tocado = array(); // para crear se usa el mismo método save del modelo, hay que montar el objeto if (!empty($_POST['email'])) { $user->email = $_POST['email']; $tocado[] = Text::_('el email'); } if (!empty($_POST['password'])) { $user->password = $_POST['password']; $tocado[] = Text::_('la contraseña'); } if (!empty($tocado) && $user->update($errors)) { // Evento Feed $log = new Feed(); $log->setTarget($user->id, 'user'); $log->populate(Text::_('Operación sobre usuario'), '/admin/users', \vsprintf('El admin %s ha %s del usuario %s', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Tocado ' . implode(' y ', $tocado)), Feed::item('user', $user->name, $user->id)))); $log->doAdmin('user'); unset($log); // mensaje de ok y volvemos a la lista de usuarios Message::Info(Text::_('Datos actualizados')); throw new Redirection('/admin/users'); } else { // si hay algun error volvemos a poner los datos en el formulario $data = $_POST; Message::Error(Text::_('No se ha guardado correctamente. ') . implode('<br />', $errors)); } } // vista de editar usuario return new View('view/admin/index.html.php', array('folder' => 'users', 'file' => 'edit', 'user' => $user, 'data' => $data, 'nodes' => $nodes)); break; case 'manage': // si llega post: ejecutamos + mensaje + seguimos editando // operación y acción para el feed $mngSa = static::_manageSubAct(); $sql = $mngSa[$subaction]['sql']; $log_action = $mngSa[$subaction]['log']; if (!empty($sql)) { $user = Model\User::getMini($id); if (Model\User::query($sql, array(':user' => $id))) { // mensaje de ok y volvemos a la gestion del usuario // Message::Info('Ha <strong>' . $log_action . '</strong> al usuario <strong>'.$user->name.'</strong> CORRECTAMENTE'); $log_text = 'El admin %s ha %s al usuario %s'; // procesos adicionales switch ($subaction) { case 'admin': case 'noadmin': // @NODESYS : this admin/noadmin subactions are here for NODESYS module extra break; case 'translator': // le ponemos todos los idiomas (excepto el español) $sql = "INSERT INTO user_translang (user, lang) SELECT '{$id}' as user, id as lang FROM `lang` WHERE id != 'es'"; Model\User::query($sql); break; case 'notranslator': // quitamos los idiomas $sql = "DELETE FROM user_translang WHERE user = :user"; Model\User::query($sql, array(':user' => $id)); break; } } else { // mensaje de error y volvemos a la gestion del usuario Message::Error('Ha FALLADO cuando ha <strong>' . $log_action . '</strong> al usuario <strong>' . $id . '</strong>'); $log_text = 'Al admin %s le ha <strong>FALLADO</strong> cuando ha %s al usuario %s'; } // Evento Feed $log = new Feed(); $log->setTarget($user->id, 'user'); $log->populate(Text::_('Operación sobre usuario'), '/admin/users', \vsprintf($log_text, array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', $log_action), Feed::item('user', $user->name, $user->id)))); $log->doAdmin('user'); unset($log); throw new Redirection('/admin/users/manage/' . $id); } $user = Model\User::get($id); $viewData = array('folder' => 'users', 'file' => 'manage', 'user' => $user, 'nodes' => $nodes); $viewData['roles'] = Model\User::getRolesList(); $viewData['langs'] = Lang::getAll(); // quitamos el español unset($viewData['langs']['es']); // vista de gestión de usuario return new View('view/admin/index.html.php', $viewData); break; // aplicar idiomas // aplicar idiomas case 'translang': if (!isset($_POST['user'])) { Message::Error(Text::_('Hemos perdido de vista al usuario')); throw new Redirection('/admin/users'); } else { $user = $_POST['user']; } $sql = "DELETE FROM user_translang WHERE user = :user"; Model\User::query($sql, array(':user' => $user)); $anylang = false; foreach ($_POST as $key => $value) { if (\substr($key, 0, \strlen('lang_')) == 'lang_') { $sql = "INSERT INTO user_translang (user, lang) VALUES (:user, :lang)"; if (Model\User::query($sql, array(':user' => $user, ':lang' => $value))) { $anylang = true; } } } if (!$anylang) { Message::Error(Text::_('No se ha seleccionado ningún idioma, este usuario tendrá problemas en su panel de traducción!')); } else { Message::Info(Text::_('Se han aplicado al traductor los idiomas seleccionados')); } throw new Redirection('/admin/users/manage/' . $user); break; case 'impersonate': $user = Model\User::get($id); // vista de acceso a suplantación de usuario return new View('view/admin/index.html.php', array('folder' => 'users', 'file' => 'impersonate', 'user' => $user, 'nodes' => $nodes)); break; case 'move': $user = Model\User::get($id); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $values = array(':id' => $id, ':node' => $_POST['node']); try { $sql = "UPDATE user SET node = :node WHERE id = :id"; if (Model\User::query($sql, $values)) { $log_text = 'El admin %s ha <span class="red">movido</span> el usuario %s al nodo %s'; } else { $log_text = 'Al admin %s le ha <span class="red">fallado al mover</span> el usuario %s al nodo %s'; } // Evento Feed $log = new Feed(); $log->setTarget($user->id, 'user'); $log->populate('User cambiado de nodo (admin)', '/admin/users', \vsprintf($log_text, array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('user', $user->name, $user->id), Feed::item('user', $nodes[$_POST['node']])))); Message::Error($log->html); $log->doAdmin('user'); unset($log); throw new Redirection('/admin/users'); } catch (\PDOException $e) { Message::Error("Ha fallado! " . $e->getMessage()); } } // vista de acceso a suplantación de usuario return new View('view/admin/index.html.php', array('folder' => 'users', 'file' => 'move', 'user' => $user, 'nodes' => $nodes)); break; case 'list': default: if (!empty($filters['filtered'])) { $users = Model\User::getAll($filters, $node); } else { $users = array(); } $status = array('active' => Text::_('Activo'), 'inactive' => Text::_('Inactivo')); $interests = Model\User\Interest::getAll(); $roles = Model\User::getRolesList(); $roles['user'] = Text::_('Solo usuario'); $types = array('creators' => Text::_('Impulsores'), 'investors' => Text::_('Cofinanciadores'), 'supporters' => Text::_('Colaboradores')); $orders = array('created' => Text::_('Fecha de alta'), 'name' => Text::_('Alias'), 'id' => Text::_('User'), 'amount' => Text::_('Cantidad'), 'projects' => Text::_('Proyectos')); // proyectos con aportes válidos $projects = Model\Invest::projects(true, $node); return new View('view/admin/index.html.php', array('folder' => 'users', 'file' => 'list', 'users' => $users, 'filters' => $filters, 'status' => $status, 'interests' => $interests, 'roles' => $roles, 'types' => $types, 'nodes' => $nodes, 'projects' => $projects, 'orders' => $orders)); break; } }
* Goteo 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, either version 3 of the License, or * (at your option) any later version. * * Goteo 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 Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>. * */ use Goteo\Library\i18n\Lang; $langs = Lang::getAll(true); ?> <ul class="lang"> <?php foreach ($langs as $lang) { ?> <?php if ($lang->id == LANG) { continue; } ?> <li > <a href="?lang=<?php echo $lang->id; ?>
public function translates($option = 'overview', $action = 'list', $id = null) { $user = $_SESSION['user']; $errors = array(); $langs = \Goteo\Library\i18n\Lang::getAll(); if ($action == 'lang' && !empty($_POST['lang'])) { $_SESSION['translate_lang'] = $_POST['lang']; } elseif (empty($_SESSION['translate_lang'])) { $_SESSION['translate_lang'] = 'en'; } $projects = Model\User\Translate::getMyProjects($user->id); // al seleccionar controlamos: translate_type if ($action == 'select' && !empty($_POST['type'])) { unset($_SESSION['translate_project']); // quitamos el proyecto de traducción $type = $_POST['type']; if (!empty($_POST[$type])) { $_SESSION['translate_type'] = $type; $_SESSION['translate_' . $type] = $_POST[$type]; } else { $_SESSION['translate_type'] = 'profile'; } } // view data basico para esta seccion $viewData = array('menu' => self::menu(), 'section' => __FUNCTION__, 'option' => $option, 'action' => $action, 'langs' => $langs, 'projects' => $projects, 'errors' => $errors, 'success' => $success); // aqui, segun lo que este traduciendo, necesito tener un proyecto de trabajo, una convocatoria o mi perfil personal switch ($_SESSION['translate_type']) { case 'project': try { // si lo que tenemos en sesion no es una instancia de proyecto (es una id de proyecto) if ($_SESSION['translate_project'] instanceof Model\Project) { $project = Model\Project::get($_SESSION['translate_project']->id, $_SESSION['translate_lang']); } else { $project = Model\Project::get($_SESSION['translate_project'], $_SESSION['translate_lang']); } } catch (\Goteo\Core\Error $e) { $project = null; } if (!$project instanceof Model\Project) { Message::Error('Ha fallado al cargar los datos del proyecto'); $_SESSION['translate_type'] = 'profile'; throw new Redirection('/dashboard/translates'); } $_SESSION['translate_project'] = $project; $project->lang_name = $langs[$project->lang]->name; unset($viewData['langs'][$project->lang]); // quitamos el idioma original //// Control de traduccion de proyecto if ($option == 'updates') { // sus novedades $blog = Model\Blog::get($project->id); if ($action != 'edit') { $action = 'list'; } } // tratar lo que llega por post para guardar los datos if ($_SERVER['REQUEST_METHOD'] == 'POST') { switch ($option) { case 'profile': if ($action == 'save') { $user = Model\User::get($_POST['id'], $_SESSION['translate_lang']); $user->about_lang = $_POST['about']; $user->keywords_lang = $_POST['keywords']; $user->contribution_lang = $_POST['contribution']; $user->lang = $_SESSION['translate_lang']; $user->saveLang($errors); } break; case 'overview': if ($action == 'save') { $project->description_lang = $_POST['description']; $project->motivation_lang = $_POST['motivation']; $project->video_lang = $_POST['video']; $project->about_lang = $_POST['about']; $project->goal_lang = $_POST['goal']; $project->related_lang = $_POST['related']; $project->reward_lang = $_POST['reward']; $project->keywords_lang = $_POST['keywords']; $project->media_lang = $_POST['media']; $project->subtitle_lang = $_POST['subtitle']; $project->lang_lang = $_SESSION['translate_lang']; $project->saveLang($errors); } break; case 'costs': if ($action == 'save') { foreach ($project->costs as $key => $cost) { if (isset($_POST['cost-' . $cost->id . '-cost'])) { $cost->cost_lang = $_POST['cost-' . $cost->id . '-cost']; $cost->description_lang = $_POST['cost-' . $cost->id . '-description']; $cost->lang = $_SESSION['translate_lang']; $cost->saveLang($errors); } } } break; case 'rewards': if ($action == 'save') { foreach ($project->social_rewards as $k => $reward) { if (isset($_POST['social_reward-' . $reward->id . '-reward'])) { $reward->reward_lang = $_POST['social_reward-' . $reward->id . '-reward']; $reward->description_lang = $_POST['social_reward-' . $reward->id . '-description']; $reward->other_lang = $_POST['social_reward-' . $reward->id . '-other']; $reward->lang = $_SESSION['translate_lang']; $reward->saveLang($errors); } } foreach ($project->individual_rewards as $k => $reward) { if (isset($_POST['individual_reward-' . $reward->id . '-reward'])) { $reward->reward_lang = $_POST['individual_reward-' . $reward->id . '-reward']; $reward->description_lang = $_POST['individual_reward-' . $reward->id . '-description']; $reward->other_lang = $_POST['individual_reward-' . $reward->id . '-other']; $reward->lang = $_SESSION['translate_lang']; $reward->saveLang($errors); } } } break; case 'supports': if ($action == 'save') { // tratar colaboraciones existentes foreach ($project->supports as $key => $support) { if (isset($_POST['support-' . $support->id . '-support'])) { // guardamos los datos traducidos $support->support_lang = $_POST['support-' . $support->id . '-support']; $support->description_lang = $_POST['support-' . $support->id . '-description']; $support->lang = $_SESSION['translate_lang']; $support->saveLang($errors); // actualizar el Mensaje correspondiente, solamente actualizar $msg = Model\Message::get($support->thread); $msg->message_lang = "{$support->support_lang}: {$support->description_lang}"; $msg->lang = $_SESSION['translate_lang']; $msg->saveLang($errors); } } } break; case 'updates': if (empty($_POST['blog']) || empty($_POST['id'])) { break; } $post = Model\Blog\Post::get($_POST['id']); $post->title_lang = $_POST['title']; $post->text_lang = $_POST['text']; $post->media_lang = $_POST['media']; $post->legend_lang = $_POST['legend']; $post->lang = $_SESSION['translate_lang']; $post->saveLang($errors); $action = 'edit'; break; } } switch ($option) { case 'profile': $viewData['user'] = Model\User::get($project->owner, $_SESSION['translate_lang']); break; case 'overview': break; case 'costs': if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/cost-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; } } } break; case 'rewards': if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/((social)|(individual))_reward-(\\d+)-edit/', $k)) { $viewData[$k] = true; break; } } } break; case 'supports': if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/support-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; break; } } } break; // publicar actualizaciones // publicar actualizaciones case 'updates': $viewData['blog'] = $blog; if ($action == 'edit') { $post = Model\Blog\Post::get($id, $_SESSION['translate_lang']); $viewData['post'] = $post; } else { $posts = array(); foreach ($blog->posts as $post) { $posts[] = Model\Blog\Post::get($post->id, $_SESSION['translate_lang']); } $viewData['posts'] = $posts; } break; } $viewData['project'] = $project; //// FIN Control de traduccion de proyecto break; default: // profile $viewData['option'] = 'profile'; unset($langs['es']); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($action == 'save') { $user = Model\User::get($_POST['id'], $_SESSION['translate_lang']); $user->about_lang = $_POST['about']; $user->keywords_lang = $_POST['keywords']; $user->contribution_lang = $_POST['contribution']; $user->lang = $_SESSION['translate_lang']; $user->saveLang($errors); } } $viewData['user'] = Model\User::get($user->id, $_SESSION['translate_lang']); } if (!empty($errors)) { Message::Error('HA HABIDO ERRORES: <br />' . implode('<br />', $errors)); } return new View('view/dashboard/index.html.php', $viewData); }