/** * @return string */ public function get_all_parent() { $this->result[] = \Goteo\Model\Skill::getAllParent(); return $this->output(); }
public function edit($id, $step = 'userProfile') { if (!isset($_SESSION['user']->roles['project_owner'])) { throw new Redirection('/dashboard/profile/'); } $project = Model\Project::get($id, null); // para que tenga todas las imágenes $project->gallery = Model\Image::getAll($id, 'project'); // aunque pueda acceder edit, no lo puede editar si if ($project->owner != $_SESSION['user']->id && (isset($_SESSION['admin_node']) && $_SESSION['admin_node'] != \GOTEO_NODE) && (isset($_SESSION['admin_node']) && $project->node != $_SESSION['admin_node']) && !isset($_SESSION['user']->roles['superadmin']) && (isset($_SESSION['user']->roles['checker']) && !Model\User\Review::is_assigned($_SESSION['user']->id, $project->id))) { Message::Info(Text::_('No tienes permiso para editar este proyecto')); throw new Redirection('/admin/projects'); } // si no tenemos SESSION stepped es porque no venimos del create if (!isset($_SESSION['stepped'])) { $_SESSION['stepped'] = array('userProfile' => 'userProfile', 'userPersonal' => 'userPersonal', 'overview' => 'overview', 'costs' => 'costs', 'rewards' => 'rewards', 'supports' => 'supports'); } if ($project->status != 1 && !ACL::check('/project/edit/todos')) { // solo puede estar en preview $step = 'preview'; $steps = array('preview' => array('name' => Text::get('step-7'), 'title' => Text::get('step-preview'), 'offtopic' => true)); } else { // todos los pasos // entrando, por defecto, en el paso especificado en url $steps = array('userProfile' => array('name' => Text::get('step-1'), 'title' => Text::get('step-userProfile'), 'offtopic' => true), 'userPersonal' => array('name' => Text::get('step-2'), 'title' => Text::get('step-userPersonal'), 'offtopic' => true), 'overview' => array('name' => Text::get('step-3'), 'title' => Text::get('step-overview')), 'costs' => array('name' => Text::get('step-4'), 'title' => Text::get('step-costs')), 'rewards' => array('name' => Text::get('step-5'), 'title' => Text::get('step-rewards')), 'supports' => array('name' => Text::get('step-6'), 'title' => Text::get('step-supports')), 'preview' => array('name' => Text::get('step-7'), 'title' => Text::get('step-preview'), 'offtopic' => true)); } foreach ($_REQUEST as $k => $v) { if (strncmp($k, 'view-step-', 10) === 0 && !empty($v) && !empty($steps[substr($k, 10)])) { $step = substr($k, 10); } } if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST)) { $errors = array(); // errores al procesar, no son errores en los datos del proyecto foreach ($steps as $id => &$data) { if (call_user_func_array(array($this, "process_{$id}"), array(&$project, &$errors))) { // si un process devuelve true es que han enviado datos de este paso, lo añadimos a los pasados if (!in_array($id, $_SESSION['stepped'])) { $_SESSION['stepped'][$id] = $id; } } } // guardamos los datos que hemos tratado y los errores de los datos $project->save($errors); // hay que mostrar errores en la imagen if (!empty($errors['image'])) { $project->errors['overview']['image'] = $errors['image']; $project->okeys['overview']['image'] = null; } // si estan enviando el proyecto a revisión if (isset($_POST['process_preview']) && isset($_POST['finish'])) { $errors = array(); $old_id = $project->id; if ($project->ready($errors)) { if ($_SESSION['project']->id == $old_id) { $_SESSION['project'] = $project; } // email a los de goteo $mailHandler = new Mail(); $mailHandler->reply = $project->user->email; $mailHandler->replyName = "{$project->user->name}"; $mailHandler->to = \GOTEO_MAIL; $mailHandler->toName = 'Revisor de proyectos'; $mailHandler->subject = 'Proyecto ' . $project->name . ' enviado a valoración'; $mailHandler->content = '<p>Han enviado un nuevo proyecto a revisión</p><p>El nombre del proyecto es: <span class="message-highlight-blue">' . $project->name . '</span> <br />y se puede ver en <span class="message-highlight-blue"><a href="' . SITE_URL . '/project/' . $project->id . '">' . SITE_URL . '/project/' . $project->id . '</a></span></p>'; $mailHandler->html = true; $mailHandler->template = 0; if ($mailHandler->send($errors)) { Message::Info(Text::get('project-review-request_mail-success')); } else { Message::Error(Text::get('project-review-request_mail-fail')); Message::Error(implode('<br />', $errors)); } unset($mailHandler); // email al autor // Obtenemos la plantilla para asunto y contenido $template = Template::get(8); // Sustituimos los datos $subject = str_replace('%PROJECTNAME%', $project->name, $template->title); // En el contenido: $search = array('%USERNAME%', '%PROJECTNAME%'); $replace = array($project->user->name, $project->name); $content = \str_replace($search, $replace, $template->text); $mailHandler = new Mail(); $mailHandler->to = $project->user->email; $mailHandler->toName = $project->user->name; $mailHandler->subject = $subject; $mailHandler->content = $content; $mailHandler->html = true; $mailHandler->template = $template->id; if ($mailHandler->send($errors)) { Message::Info(Text::get('project-review-confirm_mail-success')); } else { Message::Error(Text::get('project-review-confirm_mail-fail')); Message::Error(implode('<br />', $errors)); } unset($mailHandler); // Evento Feed $log = new Feed(); $log->setTarget($project->id); $log->populate('El proyecto ' . $project->name . ' se ha enviado a revision', '/project/' . $project->id, \vsprintf('%s ha inscrito el proyecto %s para <span class="red">revisión</span>, el estado global de la información es del %s', array(Feed::item('user', $project->user->name, $project->user->id), Feed::item('project', $project->name, $project->id), Feed::item('relevant', $project->progress . '%')))); $log->doAdmin('project'); unset($log); throw new Redirection("/dashboard?ok"); } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST)) { throw new Error(Error::INTERNAL, 'FORM CAPACITY OVERFLOW'); } //re-evaluar el proyecto $project->check(); // variables para la vista $viewData = array('project' => $project, 'steps' => $steps, 'step' => $step); // segun el paso añadimos los datos auxiliares para pintar switch ($step) { case 'userProfile': $owner = Model\User::get($project->owner, null); // si es el avatar por defecto no lo mostramos aqui if ($owner->avatar->id == 1) { unset($owner->avatar); } $viewData['user'] = $owner; $viewData['interests'] = Model\User\Interest::getAll(); $viewData['skills'] = Model\Skill::getAll(); if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/web-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; } } if (!empty($_POST['web-add'])) { $last = end($owner->webs); if ($last !== false) { $viewData["web-{$last->id}-edit"] = true; } } } break; case 'userPersonal': $viewData['account'] = Model\Project\Account::get($project->id); break; case 'overview': $viewData['categories'] = Model\Project\Category::getAll(); // $viewData['currently'] = Model\Project::currentStatus(); // $viewData['scope'] = Model\Project::scope(); $viewData['project_location'] = Model\Project::yokohamaLocation(); break; case 'costs': $viewData['types'] = Model\Project\Cost::types(); if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/cost-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; } } if (!empty($_POST['cost-add'])) { $last = end($project->costs); if ($last !== false) { $viewData["cost-{$last->id}-edit"] = true; } } } break; case 'rewards': $viewData['itypes'] = Model\Project\Reward::icons('individual'); $viewData['stypes'] = Model\Project\Reward::icons('social'); $viewData['licenses'] = Model\Project\Reward::licenses(); // $viewData['types'] = Model\Project\Support::types(); if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/((social)|(individual))_reward-(\\d+)-edit/', $k)) { $viewData[$k] = true; } } if (!empty($_POST['social_reward-add'])) { $last = end($project->social_rewards); if ($last !== false) { $viewData["social_reward-{$last->id}-edit"] = true; } } if (!empty($_POST['individual_reward-add'])) { $last = end($project->individual_rewards); if ($last !== false) { $viewData["individual_reward-{$last->id}-edit"] = true; } } } break; case 'supports': $viewData['types'] = Model\Project\Support::types(); $viewData['skills'] = Model\Skill::getAll(); if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/support-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; } } if (!empty($_POST['support-add'])) { $last = end($project->supports); if ($last !== false) { $viewData["support-{$last->id}-edit"] = true; } } } break; case 'preview': $success = array(); if (empty($project->errors)) { $success[] = Text::get('guide-project-success-noerrors'); } if ($project->finishable) { $success[] = Text::get('guide-project-success-minprogress'); $success[] = Text::get('guide-project-success-okfinish'); } $viewData['success'] = $success; $viewData['types'] = Model\Project\Cost::types(); break; } $view = new View("view/project/edit.html.php", $viewData); return $view; }
* 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\Model\Category, Goteo\Model\Skill, Goteo\Model\Icon, Goteo\Library\Location, Goteo\Library\Text; $categories = Category::getList(); // categorias que se usan en proyectos $locations = Location::getList(); //localizaciones de royectos $rewards = Icon::getList(); // iconos que se usan en proyectos $skills = Skill::getList(); // スキル取得 $params = $this['params']; ?> <div class="widget searcher"> <form method="post" action="/discover/results"> <div class="text-filter"> <label for="text-query"><?php echo Text::get('discover-searcher-bycontent-header'); ?></label> <input type="text" id="text-query" name="query" size="48" value="<?php echo \htmlspecialchars($params['query']); ?>" /> <br clear="all" /> </div> <div class="filter"> <label for="skills"><?php echo Text::get('discover-searcher-byskill-header'); ?></label> <select id="skills" name="skills[]" multiple size="10"> <option class="all" value="all"<?php if (empty($params['skills'])) echo ' selected="selected"'; ?>><?php echo Text::get('discover-searcher-bycategory-all'); ?></option>
public function profile($option = 'profile', $action = 'edit') { // tratamos el post segun la opcion y la acion $user = $_SESSION['user']; // salto al perfil público if ($option == 'public') { throw new Redirection('/user/profile/' . $user->id); } // vip/recomendador tiene una imagen adicional $vip = $option == 'profile' && isset($user->roles['vip']) ? Model\User\Vip::get($user->id) : null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $log_action = null; $errors = array(); switch ($option) { // perfil publico case 'profile': Dashboard\Profile::process_profile($user, $vip, $errors, $log_action); break; // datos personales // datos personales case 'personal': Dashboard\Profile::process_personal($user->id, $errors, $log_action); break; //cambio de email y contraseña //cambio de email y contraseña case 'access': Dashboard\Profile::process_access($user, $errors, $log_action); break; // preferencias de notificación // preferencias de notificación case 'preferences': Dashboard\Profile::process_preferences($user->id, $errors, $log_action); break; } if (!empty($log_action)) { // Evento Feed $log = new Feed(); $log->setTarget($user->id, 'user'); $log->populate('usuario ' . $log_action . ' (dashboard)', '/admin/users', \vsprintf('%s ha %s desde su dashboard', array(Feed::item('user', $user->name, $user->id), Feed::item('relevant', $log_action)))); $log->doAdmin('user'); unset($log); } } $viewData = array('menu' => self::menu(), 'section' => __FUNCTION__, 'option' => $option, 'action' => $action, 'errors' => $errors, 'user' => $user); switch ($option) { case 'profile': $viewData['interests'] = Model\User\Interest::getAll(); //$viewData['skills'] = Model\User\Skill::getAll(); $viewData['skills'] = Model\Skill::getAll(); if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/web-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; break; } } } if (!empty($_POST['web-add'])) { $last = end($user->webs); if ($last !== false) { $viewData["web-{$last->id}-edit"] = true; } } if (isset($user->roles['vip'])) { $viewData['vip'] = Model\User\Vip::get($user->id); } break; case 'personal': $viewData['personal'] = Model\User::getPersonal($user->id); break; case 'access': // si es recover, en contraseña actual tendran que poner el username if ($action == 'recover') { $viewData['message'] = Text::get('dashboard-password-recover-advice'); } break; case 'preferences': $viewData['preferences'] = Model\User::getPreferences($user->id); break; } return new View(VIEW_PATH . '/dashboard/index.html.php', $viewData); }
public static function process($action = 'list', $id = null, $filters = array()) { $log_text = null; $errors = array(); // multiples usos $nodes = array(); if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['id'])) { $projData = Model\Project::get($_POST['id']); if (empty($projData->id)) { Message::Error(Text::get('admin-projects-error-project') . $_POST['id'] . Text::get('admin-projects-error-there')); throw new Redirection('/admin/projects/images/' . $id); } if (isset($_POST['save-dates'])) { $fields = array('created', 'updated', 'published', 'success', 'closed', 'passed'); $set = ''; $values = array(':id' => $projData->id); foreach ($fields as $field) { if ($set != '') { $set .= ", "; } $set .= "`{$field}` = :{$field} "; if (empty($_POST[$field]) || $_POST[$field] == '0000-00-00') { $_POST[$field] = null; } $values[":{$field}"] = $_POST[$field]; } try { $sql = "UPDATE project SET " . $set . " WHERE id = :id"; if (Model\Project::query($sql, $values)) { $log_text = Text::_('El admin %s ha <span class="red">tocado las fechas</span> del proyecto ') . $projData->name . ' %s'; } else { $log_text = Text::_('Al admin %s le ha <span class="red">fallado al tocar las fechas</span> del proyecto ') . $projData->name . ' %s'; } } catch (\PDOException $e) { Message::Error(Text::get('admin-projects-error-save-fail') . $e->getMessage()); } } elseif (isset($_POST['save-accounts'])) { $accounts = Model\Project\Account::get($projData->id); $accounts->bank = $_POST['bank']; $accounts->bank_owner = $_POST['bank_owner']; $accounts->paypal = $_POST['paypal']; $accounts->paypal_owner = $_POST['paypal_owner']; if ($accounts->save($errors)) { Message::Info(Text::get('admin-projects-info-update-account') . $projData->name); } else { Message::Error(implode('<br />', $errors)); } } elseif ($action == 'images') { $todook = true; if (!empty($_POST['move'])) { $direction = $_POST['action']; Model\Project\Image::$direction($id, $_POST['move'], $_POST['section']); } foreach ($_POST as $key => $value) { $parts = explode('_', $key); if ($parts[1] == 'image' && in_array($parts[0], array('section', 'url'))) { if (Model\Project\Image::update($id, $parts[2], $parts[0], $value)) { // OK } else { $todook = false; Message::Error(Text::get('admin-projects-info-data-save') . " {$parts[0]} -> {$value}"); } } } if ($todook) { Message::Info(Text::_('Se han actualizado los datos')); } throw new Redirection('/admin/projects/images/' . $id); } elseif ($action == 'rebase') { $todook = true; if ($_POST['proceed'] == 'rebase' && !empty($_POST['newid'])) { $newid = $_POST['newid']; // pimero miramos que no hay otro proyecto con esa id $test = Model\Project::getMini($newid); if ($test->id == $newid) { Message::Error(Text::get('admin-projects-error-id-notempty')); throw new Redirection('/admin/projects/rebase/' . $id); } if ($projData->status >= 3 && $_POST['force'] != 1) { Message::Error(Text::_('El proyecto no está ni en Edición ni en Revisión, no se modifica nada.')); throw new Redirection('/admin/projects/rebase/' . $id); } if ($projData->rebase($newid)) { Message::Info(Text::get('admin-projects-info-selectproject') . ' -> <a href="' . SITE_URL . '/project/' . $newid . '" target="_blank">' . $projData->name . '</a>'); throw new Redirection('/admin/projects'); } else { Message::Info(Text::_('Ha fallado algo en el rebase, verificar el proyecto') . ' -> <a href="' . SITE_URL . '/project/' . $projData->id . '" target="_blank">' . $projData->name . ' (' . $id . ')</a>'); throw new Redirection('/admin/projects/rebase/' . $id); } } } } /* * switch action, * proceso que sea, * redirect * */ if (isset($id)) { $project = Model\Project::get($id); } switch ($action) { case 'review': // pasar un proyecto a revision if ($project->ready($errors)) { $redir = '/admin/reviews/add/' . $project->id; $log_text = Text::_('El admin %s ha pasado el proyecto %s al estado <span class="red">Revision</span>'); } else { $log_text = Text::_('Al admin %s le ha fallado al pasar el proyecto %s al estado <span class="red">Revision</span>'); } break; case 'publish': // poner un proyecto en campa�a if ($project->publish($errors)) { $log_text = Text::_('El admin %s ha pasado el proyecto %s al estado <span class="red">en Campa�a</span>'); } else { $log_text = Text::_('Al admin %s le ha fallado al pasar el proyecto %s al estado <span class="red">en Campa�a</span>'); } break; case 'cancel': // descartar un proyecto por malo if ($project->cancel($errors)) { $log_text = Text::_('El admin %s ha pasado el proyecto %s al estado <span class="red">Descartado</span>'); } else { $log_text = Text::_('Al admin %s le ha fallado al pasar el proyecto %s al estado <span class="red">Descartado</span>'); } break; case 'enable': // si no esta en edicion, recuperarlo if ($project->enable($errors)) { $log_text = Text::_('El admin %s ha pasado el proyecto %s al estado <span class="red">Edicion</span>'); } else { $log_text = Text::_('Al admin %s le ha fallado al pasar el proyecto %s al estado <span class="red">Edicion</span>'); } break; case 'fulfill': // marcar que el proyecto ha cumplido con los retornos colectivos if ($project->satisfied($errors)) { $log_text = Text::_('El admin %s ha pasado el proyecto %s al estado <span class="red">Retorno cumplido</span>'); } else { $log_text = Text::_('Al admin %s le ha fallado al pasar el proyecto %s al estado <span class="red">Retorno cumplido</span>'); } break; case 'unfulfill': // dar un proyecto por financiado manualmente if ($project->rollback($errors)) { $log_text = Text::_('El admin %s ha pasado el proyecto %s al estado <span class="red">Financiado</span>'); } else { $log_text = Text::_('Al admin %s le ha fallado al pasar el proyecto %s al estado <span class="red">Financiado</span>'); } break; } if (isset($log_text)) { // Evento Feed $log = new Feed(); $log->setTarget($project->id); $log->populate(Text::_('Cambio estado/fechas/cuentas/nodo de un proyecto desde el admin'), '/admin/projects', \vsprintf($log_text, array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('project', $project->name, $project->id)))); $log->doAdmin('admin'); Message::Info($log->html); if (!empty($errors)) { Message::Error(implode('<br />', $errors)); } if ($action == 'publish') { // si es publicado, hay un evento publico $log->populate($project->name, '/project/' . $project->id, Text::html('feed-new_project'), $project->gallery[0]->id); $log->doPublic('projects'); } unset($log); if (empty($redir)) { throw new Redirection('/admin/projects/list'); } else { throw new Redirection($redir); } } if ($action == 'report') { // informe financiero // Datos para el informe de transacciones correctas $Data = Model\Invest::getReportData($project->id, $project->status, $project->round, $project->passed); return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'report', 'project' => $project, 'Data' => $Data)); } if ($action == 'dates') { // cambiar fechas return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'dates', 'project' => $project)); } if ($action == 'accounts') { $accounts = Model\Project\Account::get($project->id); // cambiar fechas return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'accounts', 'project' => $project, 'accounts' => $accounts)); } if ($action == 'images') { // imagenes $images = array(); // secciones $sections = Model\Project\Image::sections(); foreach ($sections as $sec => $secName) { $secImages = Model\Project\Image::get($project->id, $sec); foreach ($secImages as $img) { $images[$sec][] = $img; } } return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'images', 'project' => $project, 'images' => $images, 'sections' => $sections)); } if ($action == 'move') { // cambiar el nodo return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'move', 'project' => $project, 'nodes' => $nodes)); } if ($action == 'rebase') { // cambiar la id return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'rebase', 'project' => $project)); } // Rechazo express if ($action == 'reject') { if (empty($project)) { Message::Error(Text::get('admin-projects-error-nooperate-project')); } else { // Obtenemos la plantilla para asunto y contenido $template = Template::get(40); // Sustituimos los datos $subject = str_replace('%PROJECTNAME%', $project->name, $template->title); $search = array('%USERNAME%', '%PROJECTNAME%'); $replace = array($project->user->name, $project->name); $content = \str_replace($search, $replace, $template->text); // iniciamos mail $mailHandler = new Mail(); $mailHandler->to = $project->user->email; $mailHandler->toName = $project->user->name; $mailHandler->subject = $subject; $mailHandler->content = $content; $mailHandler->html = true; $mailHandler->template = $template->id; if ($mailHandler->send()) { Message::Info('<strong>' . $project->user->name . '</strong>' . Text::get('admin-projects-info-sendmail-to') . '<strong>(' . $project->user->email . ')</strong>' . Text::get('admin-projects-info-sendmail')); } else { Message::Error(Text::_('Ha fallado al enviar el mail a') . '<strong>' . $project->user->name . '</strong>' . Text::_('a la dirección') . '<strong>' . $project->user->email . '</strong>'); } unset($mailHandler); } throw new Redirection('/admin/projects/list'); } if (!empty($filters['filtered'])) { $projects = Model\Project::getList($filters, $_SESSION['admin_node']); } else { $projects = array(); } $status = Model\Project::status(); $categories = Model\Project\Category::getAll(); $skills = Model\Skill::getAll(); //@CONTRACTSYS $calls = array(); // la lista de nodos la hemos cargado arriba $orders = array('name' => Text::_('Nombre'), 'updated' => Text::_('Enviado a revision')); return new View('view/admin/index.html.php', array('folder' => 'projects', 'file' => 'list', 'projects' => $projects, 'filters' => $filters, 'status' => $status, 'categories' => $categories, 'skills' => $skills, 'calls' => $calls, 'nodes' => $nodes, 'orders' => $orders)); }
* 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\Model\Category, Goteo\Model\Skill, Goteo\Model\Icon, Goteo\Library\Location, Goteo\Library\Text; $categories = Category::getList(); // categorias que se usan en proyectos $locations = Location::getList(); //localizaciones de royectos $rewards = Icon::getList(); // iconos que se usan en proyectos $skills = Skill::getList(); // スキル取得 $params = $this['params']; //var_dump($locations); //exit; ?> <div class="widget searcher"> <form method="post" action="/discover/results"> <div class="text-filter"> <label for="text-query"><?php echo Text::get('discover-searcher-bycontent-header'); ?> </label> <input type="text" id="text-query" name="query" size="48" value="<?php echo \htmlspecialchars($params['query']); ?>
public static function process($action = 'list', $id = null, $filters = array(), $subaction = '') { // multiples usos $nodes = array(); $node = isset($_SESSION['admin_node']) ? $_SESSION['admin_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::get('admin-users-info-update')); throw new Redirection('/admin/users'); } else { // si hay algun error volvemos a poner los datos en el formulario $data = $_POST; Message::Error(Text::get('admin-users-error-save-fail') . 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 = Text::_('El admin %s ha %s al usuario %s'); $onNode = \GOTEO_NODE; // procesos adicionales switch ($subaction) { case 'admin': /* if ($onNode->assign($id)) { Message::Info(Text::_('El nuevo admin se ha añadido a los administradores del nodo') . '<strong>'.$onNode->name.'</strong>.'); } else{ Message::Error(Text::_('ERROR!!! El nuevo admin no se ha podido añadir a los administradores del nodo') . '<strong>'.$onNode->name.'</strong>.' . Text::_('Contactar con el superadmin')); } */ break; case 'noadmin': /* if ($onNode->unassign($id)) { Message::Info(Text::_('El ex-admin se ha quitado de los administradores del nodo') . '<strong>'.$onNode->name.'</strong>.'); } else{ Message::Error(Text::_('ERROR!!! El ex-admin no se ha podido quitar de los administradores del nodo') . '<strong>'.$onNode->name.'</strong>.' . Text::_('Contactar con el superadmin')); } */ 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(Text::_('Ha FALLADO cuando ha') . ' <strong>' . $log_action . '</strong> ' . Text::_('al usuario') . '<strong>' . $id . '</strong>'); $log_text = 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::get('admin-user-error-nouser')); 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::get('admin-user-info-fortranslator')); } 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 = Text::_('El admin %s ha <span class="red">movido</span> el usuario %s al nodo %s'); } else { $log_text = 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(); $skills = Model\Skill::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::_('Nombre público'), 'id' => Text::_('User ID'), '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, 'skills' => $skills, 'roles' => $roles, 'types' => $types, 'nodes' => $nodes, 'projects' => $projects, 'orders' => $orders)); break; } }