public function index($show = 'activity', $category = null) { if (defined('GOTEO_EASY') && \GOTEO_EASY === true) { throw new Redirection('/'); } $page = Page::get('community'); $items = array(); $shares = array(); if (!in_array($show, array('sharemates', 'activity'))) { $show = 'activity'; } $viewData = array('description' => $page->description, 'show' => $show); switch ($show) { // compartiendo intereses global case 'sharemates': $categories = Interest::getAll(); foreach ($categories as $catId => $catName) { $gente = Interest::shareAll($catId); if (count($gente) == 0) { continue; } $shares[$catId] = $gente; } $viewData['category'] = $category; $viewData['categories'] = $categories; $viewData['shares'] = $shares; // top ten cofinanciadores en Goteo $projects = Invest::projects(true); $investors = array(); foreach ($projects as $projectId => $projectName) { foreach (Invest::investors($projectId) as $key => $investor) { if (\array_key_exists($investor->user, $investors)) { // si es otro proyecto y ya está en el array, añadir uno if ($investors[$investor->user]->lastproject != $projectId) { ++$investors[$investor->user]->projects; $investors[$investor->user]->lastproject = $projectId; } $investors[$investor->user]->amount += $investor->amount; $investors[$investor->user]->date = $investor->date; } else { $investors[$investor->user] = (object) array('user' => $investor->user, 'name' => $investor->name, 'projects' => 1, 'lastproject' => $projectId, 'avatar' => $investor->avatar, 'worth' => $investor->worth, 'amount' => $investor->amount, 'date' => $investor->date); } } } $viewData['investors'] = $investors; break; // feed público // feed público case 'activity': $items = array(); $items['goteo'] = Feed::getAll('goteo', 'public', 50); $items['projects'] = Feed::getAll('projects', 'public', 50); $items['community'] = Feed::getAll('community', 'public', 50); $viewData['items'] = $items; break; } return new View('view/community.html.php', $viewData); }
* 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\User\Interest, Goteo\Model\User\Skill, Goteo\Library\Text; $user = $this['user']; $user->about = nl2br(Text::urlink($user->about)); $interests = Interest::getAll(); $skills = Skill::getAll(null,true); ?> <div class="widget user-about"> <?php if (!empty($user->about)): ?> <div class="about"> <h4><?php echo Text::get('profile-about-header'); ?></h4> <p><?php echo $user->about ?></p> </div> <?php endif ?> <?php if (!empty($user->interests)): ?> <div class="interests">
* 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\Core\View, Goteo\Library\Worth, Goteo\Library\Text, Goteo\Model\User\Interest, Goteo\Core\Redirection; $bodyClass = 'user-profile'; include 'view/prologue.html.php'; include 'view/header.html.php'; $user = $this['user']; $worthcracy = Worth::getAll(); $categories = Interest::getAll($user->id); if (empty($categories)) { throw new Redirection('/user/profile/' . $this['user']->id); } $limit = empty($this['category']) ? 6 : 20; $shares = array(); foreach ($categories as $catId => $catName) { $gente = Interest::share($user->id, $catId, $limit); if (count($gente) == 0) { continue; } $shares[$catId] = $gente; } if (empty($shares)) { throw new Redirection('/user/profile/' . $this['user']->id); }
public function edit($id, $step = 'userProfile') { $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('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(); 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(); 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['stypes'] = Model\Project\Reward::icons('social'); $viewData['itypes'] = Model\Project\Reward::icons('individual'); $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(); 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; }
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; } }
public static function process($action = 'list', $id = null, $filters = array()) { // año fiscal $year = Model\User\Donor::$currYear; $year0 = $year; $year1 = $year - 1; $errors = array(); $node = isset($_SESSION['admin_node']) ? $_SESSION['admin_node'] : \GOTEO_NODE; // Valores de filtro $interests = Model\User\Interest::getAll(); $status = Model\Project::status(); $methods = Model\Invest::methods(); $types = array('investor' => 'Cofinanciadores', 'owner' => 'Autores', 'user' => 'Usuarios'); $roles = array('admin' => 'Administrador', 'checker' => 'Revisor', 'translator' => 'Traductor'); // una variable de sesion para mantener los datos de todo esto if (!isset($_SESSION['mailing'])) { $_SESSION['mailing'] = array(); } switch ($action) { case 'edit': $_SESSION['mailing']['receivers'] = array(); $values = array(); $sqlFields = ''; $sqlInner = ''; $sqlFilter = ''; // cargamos los destiantarios //---------------------------- // por tipo de usuario switch ($filters['type']) { case 'investor': $sqlInner .= "INNER JOIN invest\n ON invest.user = user.id\n AND (invest.status = 0 OR invest.status = 1 OR invest.status = 3 OR invest.status = 4)\n INNER JOIN project\n ON project.id = invest.project\n "; $sqlFields .= ", project.name as project"; $sqlFields .= ", project.id as projectId"; break; case 'owner': $sqlInner .= "INNER JOIN project\n ON project.owner = user.id\n "; $sqlFields .= ", project.name as project"; $sqlFields .= ", project.id as projectId"; break; default: break; } $_SESSION['mailing']['filters_txt'] = 'los <strong>' . $types[$filters['type']] . '</strong> '; if (!empty($filters['project']) && !empty($sqlInner)) { $sqlFilter .= " AND project.name LIKE (:project) "; $values[':project'] = '%' . $filters['project'] . '%'; $_SESSION['mailing']['filters_txt'] .= 'de proyectos que su nombre contenga <strong>\'' . $filters['project'] . '\'</strong> '; } elseif (empty($filters['project']) && !empty($sqlInner)) { $_SESSION['mailing']['filters_txt'] .= 'de cualquier proyecto '; } if (isset($filters['status']) && $filters['status'] > -1 && !empty($sqlInner)) { $sqlFilter .= "AND project.status = :status "; $values[':status'] = $filters['status']; $_SESSION['mailing']['filters_txt'] .= 'en estado <strong>' . $status[$filters['status']] . '</strong> '; } elseif ($filters['status'] < 0 && !empty($sqlInner)) { $_SESSION['mailing']['filters_txt'] .= 'en cualquier estado '; } if ($filters['type'] == 'investor') { if (!empty($filters['method']) && !empty($sqlInner)) { $sqlFilter .= "AND invest.method = :method "; $values[':method'] = $filters['method']; $_SESSION['mailing']['filters_txt'] .= 'mediante <strong>' . $methods[$filters['method']] . '</strong> '; } elseif (empty($filters['method']) && !empty($sqlInner)) { $_SESSION['mailing']['filters_txt'] .= 'mediante cualquier metodo '; } } if (!empty($filters['interest'])) { $sqlInner .= "INNER JOIN user_interest\n ON user_interest.user = user.id\n AND user_interest.interest = :interest\n "; $values[':interest'] = $filters['interest']; if ($filters['interest'] == 15) { $_SESSION['mailing']['filters_txt'] .= 'del grupo de testeo '; } else { $_SESSION['mailing']['filters_txt'] .= 'interesados en fin <strong>' . $interests[$filters['interest']] . '</strong> '; } } if (!empty($filters['role'])) { $sqlInner .= "INNER JOIN user_role\n ON user_role.user_id = user.id\n AND user_role.role_id = :role\n "; $values[':role'] = $filters['role']; $_SESSION['mailing']['filters_txt'] .= 'que sean <strong>' . $roles[$filters['role']] . '</strong> '; } if (!empty($filters['name'])) { $sqlFilter .= " AND ( user.name LIKE (:name) OR user.email LIKE (:name) ) "; $values[':name'] = '%' . $filters['name'] . '%'; $_SESSION['mailing']['filters_txt'] .= 'que su nombre o email contenga <strong>\'' . $filters['name'] . '\'</strong> '; } if (!empty($filters['donant'])) { if ($filters['type'] == 'investor') { $sqlFilter .= " AND invest.resign = 1\n AND invest.status IN (1, 3)\n AND invest.charged >= '{$year0}-01-01'\n AND invest.charged < '{$year1}-01-01'\n AND (project.passed IS NOT NULL AND project.passed != '0000-00-00')\n "; $_SESSION['mailing']['filters_txt'] .= 'que haya hecho algun donativo '; } else { Message::Error('Solo se filtran donantes si se envia "A los: Cofinanciadores"'); } } if ($node != \GOTEO_NODE) { $sqlFilter .= " AND user.node = :node"; $values[':node'] = $node; if (!empty($sqlInner)) { $sqlFilter .= " AND project.node = :node"; } } $sql = "SELECT\n user.id as id,\n user.id as user,\n user.name as name,\n user.email as email\n {$sqlFields}\n FROM user\n {$sqlInner}\n WHERE user.active = 1\n {$sqlFilter}\n GROUP BY user.id\n ORDER BY user.name ASC\n "; // die('<pre>'.$sql . '<br />'.print_r($values, 1).'</pre>'); if ($query = Model\User::query($sql, $values)) { foreach ($query->fetchAll(\PDO::FETCH_OBJ) as $receiver) { $_SESSION['mailing']['receivers'][$receiver->id] = $receiver; } } else { Message::Error('Fallo el SQL!!!!! <br />' . $sql . '<pre>' . print_r($values, 1) . '</pre>'); } // si no hay destinatarios, salta a la lista con mensaje de error if (empty($_SESSION['mailing']['receivers'])) { Message::Error('No se han encontrado destinatarios para ' . $_SESSION['mailing']['filters_txt']); throw new Redirection('/admin/mailing/list'); } // si hay, mostramos el formulario de envio return new View('view/admin/index.html.php', array('folder' => 'mailing', 'file' => 'edit', 'filters' => $filters, 'interests' => $interests, 'status' => $status, 'types' => $types, 'roles' => $roles)); break; case 'send': // die(\trace($_POST)); $URL = NODE_ID != GOTEO_NODE ? NODE_URL : SITE_URL; // Enviando contenido recibido a destinatarios recibidos $receivers = array(); $subject = $_POST['subject']; $templateId = !empty($_POST['template']) ? $_POST['template'] : 11; $content = \str_replace('%SITEURL%', $URL, $_POST['content']); // quito usuarios desmarcados foreach ($_SESSION['mailing']['receivers'] as $usr => $userData) { $errors = array(); $campo = 'receiver_' . $usr; if (!isset($_POST[$campo])) { $_SESSION['mailing']['receivers'][$usr]->ok = null; } else { $receivers[] = $userData; } } // montamos el mailing // - se crea un registro de tabla mail $sql = "INSERT INTO mail (id, email, html, template, node) VALUES ('', :email, :html, :template, :node)"; $values = array(':email' => 'any', ':html' => $content, ':template' => $templateId, ':node' => $node); $query = \Goteo\Core\Model::query($sql, $values); $mailId = \Goteo\Core\Model::insertId(); // - se usa el metodo initializeSending para grabar el envío (parametro para autoactivar) // - initiateSending ($mailId, $subject, $receivers, $autoactive = 0) if (\Goteo\Library\Sender::initiateSending($mailId, $subject, $receivers, 1)) { $ok = true; // Evento Feed $log = new Feed(); $log->populate('comunicación masiva a usuarios (admin)', '/admin/mailing', \vsprintf("El admin %s ha iniciado una %s a %s", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Comunicacion masiva'), $_SESSION['mailing']['filters_txt']))); $log->doAdmin('admin'); unset($log); } else { $ok = false; // Evento Feed $log = new Feed(); $log->populate('comunicación masiva a usuarios (admin)', '/admin/mailing', \vsprintf("El admin %s le ha %s una %s a %s", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'fallado'), Feed::item('relevant', 'Comunicacion masiva'), $_SESSION['mailing']['filters_txt']))); $log->doAdmin('admin'); unset($log); } return new View('view/admin/index.html.php', array('folder' => 'mailing', 'file' => 'send', 'subject' => $subject, 'interests' => $interests, 'status' => $status, 'methods' => $methods, 'types' => $types, 'roles' => $roles, 'users' => $receivers, 'ok' => $ok)); break; } return new View('view/admin/index.html.php', array('folder' => 'mailing', 'file' => 'list', 'interests' => $interests, 'status' => $status, 'methods' => $methods, 'types' => $types, 'roles' => $roles, 'filters' => $filters)); }
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(); 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/dashboard/index.html.php', $viewData); }