Example #1
0
 public function project($id)
 {
     $project = Project::getMedium($id, LANG);
     if (!$project instanceof Project) {
         throw new Redirection('/', Redirection::TEMPORARY);
     }
     return new View('view/widget/project.html.php', array('project' => $project, 'global' => true));
     throw new Redirection('/fail', Redirection::TEMPORARY);
 }
Example #2
0
 public function index()
 {
     if (isset($_GET['error'])) {
         throw new \Goteo\Core\Error('418', Text::html('fatal-error-teapot'));
     }
     // orden de los elementos en portada
     $order = Home::getAll();
     // si estamos en easy mode, quitamos el feed
     if (defined('GOTEO_EASY') && \GOTEO_EASY === true && isset($order['feed'])) {
         unset($order['feed']);
     }
     // entradas de blog
     if (isset($order['posts'])) {
         // entradas en portada
         $posts = Post::getAll();
     }
     // Proyectos destacados
     if (isset($order['promotes'])) {
         $promotes = Promote::getAll(true);
         foreach ($promotes as $key => &$promo) {
             try {
                 $promo->projectData = Project::getMedium($promo->project, LANG);
             } catch (\Goteo\Core\Error $e) {
                 unset($promotes[$key]);
             }
         }
     }
     // actividad reciente
     if (isset($order['feed'])) {
         $feed = array();
         $feed['goteo'] = Feed::getAll('goteo', 'public', 15);
         $feed['projects'] = Feed::getAll('projects', 'public', 15);
         $feed['community'] = Feed::getAll('community', 'public', 15);
     }
     // Banners siempre
     /*            $banners   = Banner::getAll(true);
     
                 foreach ($banners as $id => &$banner) {
                     
                     if (!empty($banner->project)) {
                         try {
                             $banner->project = Project::get($banner->project, LANG);
                         } catch (\Goteo\Core\Error $e) {
                             unset($banners[$id]);
                         }
                     }
                     
                 }*/
     $template = VIEW_PATH . '/index.html.php';
     return new View($template, array('banners' => $banners, 'posts' => $posts, 'promotes' => $promotes, 'order' => $order));
 }
Example #3
0
 public function confirmed($project = null, $id = null, $reward = null)
 {
     if (empty($id)) {
         Message::Error(Text::get('invest-data-error'));
         throw new Redirection('/', Redirection::TEMPORARY);
     }
     // el aporte
     $invest = Model\Invest::get($id);
     $projectData = Model\Project::getMedium($invest->project);
     // para evitar las duplicaciones de feed y email
     if (isset($_SESSION['invest_' . $invest->id . '_completed'])) {
         Message::Info(Text::get('invest-process-completed'));
         throw new Redirection($retUrl);
     }
     // segun método
     if ($invest->method == 'tpv') {
         // si el aporte no está en estado "cobrado por goteo" (1)
         if ($invest->status != '1') {
             @mail('*****@*****.**', 'Aporte tpv no pagado ' . $invest->id, 'Ha llegado a invest/confirm el aporte ' . $invest->id . ' mediante tpv sin estado cobrado (llega con estado ' . $invest->status . ')');
             // mandarlo a la pagina de aportar para que lo intente de nuevo
             // si es de Bazar, a la del producto del catálogo
             if ($project == 'bazargoteo') {
                 throw new Redirection("/bazaar/{$reward}/fail");
             } else {
                 throw new Redirection("/project/{$invest->project}/invest/?confirm=fail");
             }
         }
     }
     // Paypal solo disponible si activado
     if ($invest->method == 'paypal') {
         // hay que cambiarle el status a 0
         $invest->setStatus('0');
         // Evento Feed
         $log = new Feed();
         $log->setTarget($projectData->id);
         $log->populate('Aporte PayPal', '/admin/invests', \vsprintf("%s ha aportado %s al proyecto %s mediante PayPal", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('money', $invest->amount . ' €'), Feed::item('project', $projectData->name, $projectData->id))));
         $log->doAdmin('money');
         // evento público
         $log_html = Text::html('feed-invest', Feed::item('money', $invest->amount . ' €'), Feed::item('project', $projectData->name, $projectData->id));
         if ($invest->anonymous) {
             $log->populate(Text::get('regular-anonymous'), '/user/profile/anonymous', $log_html, 1);
         } else {
             $log->populate($_SESSION['user']->name, '/user/profile/' . $_SESSION['user']->id, $log_html, $_SESSION['user']->avatar->id);
         }
         $log->doPublic('community');
         unset($log);
     }
     // fin segun metodo
     // Feed del aporte de la campaña
     if (!empty($invest->droped) && $drop instanceof Model\Invest && is_object($callData)) {
         // Evento Feed
         $log = new Feed();
         $log->setTarget($projectData->id);
         $log->populate('Aporte riego ' . $drop->method, '/admin/invests', \vsprintf("%s ha aportado %s de %s al proyecto %s a través de la campaña %s", array(Feed::item('user', $callData->user->name, $callData->user->id), Feed::item('money', $drop->amount . ' €'), Feed::item('drop', 'Capital Riego', '/service/resources'), Feed::item('project', $projectData->name, $projectData->id), Feed::item('call', $callData->name, $callData->id))));
         $log->doAdmin('money');
         // evento público
         $log->populate($callData->user->name, '/user/profile/' . $callData->user->id, Text::html('feed-invest', Feed::item('money', $drop->amount . ' €') . ' de ' . Feed::item('drop', 'Capital Riego', '/service/resources'), Feed::item('project', $projectData->name, $projectData->id) . ' a través de la campaña ' . Feed::item('call', $callData->name, $callData->id)), $callData->user->avatar->id);
         $log->doPublic('community');
         unset($log);
     }
     // texto recompensa
     // @TODO quitar esta lacra de N recompensas porque ya es solo una recompensa siempre
     $rewards = $invest->rewards;
     array_walk($rewards, function (&$reward) {
         $reward = $reward->reward;
     });
     $txt_rewards = implode(', ', $rewards);
     // recaudado y porcentaje
     $amount = $projectData->invested;
     $percent = floor($projectData->invested / $projectData->mincost * 100);
     // email de agradecimiento al cofinanciador
     // primero monto el texto de recompensas
     //@TODO el concepto principal sería 'renuncia' (porque todos los aportes son donativos)
     if ($invest->resign) {
         // Plantilla de donativo segun la ronda
         if ($projectData->round == 2) {
             $template = Template::get(36);
             // en segunda ronda
         } else {
             $template = Template::get(28);
             // en primera ronda
         }
     } else {
         // plantilla de agradecimiento segun la ronda
         if ($projectData->round == 2) {
             $template = Template::get(34);
             // en segunda ronda
         } else {
             $template = Template::get(10);
             // en primera ronda
         }
     }
     // Dirección en el mail (y version para regalo)
     $txt_address = Text::get('invest-address-address-field') . ' ' . $invest->address->address;
     $txt_address .= '<br> ' . Text::get('invest-address-zipcode-field') . ' ' . $invest->address->zipcode;
     $txt_address .= '<br> ' . Text::get('invest-address-location-field') . ' ' . $invest->address->location;
     $txt_address .= '<br> ' . Text::get('invest-address-country-field') . ' ' . $invest->address->country;
     $txt_destaddr = $txt_address;
     $txt_address = Text::get('invest-mail_info-address') . '<br>' . $txt_address;
     // Agradecimiento al cofinanciador
     // Sustituimos los datos
     $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title);
     // En el contenido:
     $search = array('%USERNAME%', '%PROJECTNAME%', '%PROJECTURL%', '%AMOUNT%', '%REWARDS%');
     $replace = array($_SESSION['user']->name, $projectData->name, SITE_URL . '/project/' . $projectData->id, $confirm->amount, $txt_rewards);
     $content = \str_replace($search, $replace, $template->text);
     $mailHandler = new Mail();
     $mailHandler->reply = GOTEO_CONTACT_MAIL;
     $mailHandler->replyName = GOTEO_MAIL_NAME;
     $mailHandler->to = $_SESSION['user']->email;
     $mailHandler->toName = $_SESSION['user']->name;
     $mailHandler->subject = $subject;
     $mailHandler->content = $content;
     $mailHandler->html = true;
     $mailHandler->template = $template->id;
     if ($mailHandler->send($errors)) {
         Message::Info(Text::get('project-invest-thanks_mail-success'));
     } else {
         Message::Error(Text::get('project-invest-thanks_mail-fail'));
         Message::Error(implode('<br />', $errors));
     }
     unset($mailHandler);
     // Notificación al autor
     $template = Template::get(29);
     // Sustituimos los datos
     $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title);
     // En el contenido:
     $search = array('%OWNERNAME%', '%USERNAME%', '%PROJECTNAME%', '%SITEURL%', '%AMOUNT%', '%MESSAGEURL%');
     $replace = array($projectData->user->name, $_SESSION['user']->name, $projectData->name, SITE_URL, $invest->amount, SITE_URL . '/user/profile/' . $_SESSION['user']->id . '/message');
     $content = \str_replace($search, $replace, $template->text);
     $mailHandler = new Mail();
     $mailHandler->to = $projectData->user->email;
     $mailHandler->toName = $projectData->user->name;
     $mailHandler->subject = $subject;
     $mailHandler->content = $content;
     $mailHandler->html = true;
     $mailHandler->template = $template->id;
     $mailHandler->send();
     unset($mailHandler);
     // marcar que ya se ha completado el proceso de aportar
     $_SESSION['invest_' . $invest->id . '_completed'] = true;
     // log
     Model\Invest::setDetail($invest->id, 'confirmed', 'El usuario regresó a /invest/confirmed');
     if ($confirm->method == 'paypal') {
         // hay que cambiarle el status a 0
         $confirm->setStatus('0');
         /*
          * Evento Feed
          */
         $log = new Feed();
         $log->title = 'Aporte PayPal';
         $log->url = '/admin/invests';
         $log->type = 'money';
         $log_text = "%s ha aportado %s al proyecto %s mediante PayPal";
         $items = array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('money', $confirm->amount . ' &euro;'), Feed::item('project', $projectData->name, $projectData->id));
         $log->html = \vsprintf($log_text, $items);
         $log->add($errors);
         // evento público
         if ($confirm->anonymous) {
             $log->title = Text::get('regular-anonymous');
             $log->url = '/user/profile/anonymous';
             $log->image = 1;
         } else {
             $log->title = $_SESSION['user']->name;
             $log->url = '/user/profile/' . $_SESSION['user']->id;
             $log->image = $_SESSION['user']->avatar->id;
         }
         $log->scope = 'public';
         $log->type = 'community';
         $log->html = Text::html('feed-invest', Feed::item('money', $confirm->amount . ' &euro;'), Feed::item('project', $projectData->name, $projectData->id));
         $log->add($errors);
         unset($log);
     }
     // mandarlo a la pagina de gracias
     throw new Redirection("/project/{$project}/invest/?confirm=ok", Redirection::TEMPORARY);
 }
Example #4
0
 public static function invested($user, $publicOnly = true)
 {
     $projects = array();
     $sql = "SELECT project.id\r\n                    FROM  project\r\n                    INNER JOIN invest\r\n                        ON project.id = invest.project\r\n                        AND invest.user = ?\r\n                        AND invest.status IN ('0', '1', '3', '4')\r\n                    WHERE project.status < 7\r\n                    ";
     if ($publicOnly) {
         $sql .= "AND project.status >= 3\r\n                    ";
     }
     $sql .= "GROUP BY project.id\r\n                    ORDER BY name ASC\r\n                    ";
     /*
      * Restriccion de que no aparecen los que cofinancio que esten en edicion
      *  solamente no sacamos los caducados
      * project.status > 1 AND
      */
     $query = self::query($sql, array($user));
     foreach ($query->fetchAll(\PDO::FETCH_CLASS) as $proj) {
         $projects[] = \Goteo\Model\Project::getMedium($proj->id);
     }
     return $projects;
 }
Example #5
0
 public static function getMesseged($user, $publicOnly = true)
 {
     $projects = array();
     $sql = "SELECT project.id\n                    FROM  project\n                    INNER JOIN message\n                        ON project.id = message.project\n                        AND message.user = ?\n                    WHERE project.status < 7\n                    ";
     if ($publicOnly) {
         $sql .= "AND project.status >= 3\n                    ";
     }
     $sql .= "GROUP BY project.id\n                    ORDER BY name ASC\n                    ";
     $query = self::query($sql, array($user));
     foreach ($query->fetchAll(\PDO::FETCH_CLASS) as $proj) {
         $projects[] = \Goteo\Model\Project::getMedium($proj->id);
     }
     return $projects;
 }
Example #6
0
 public static function getContent($content, $lang = LANG)
 {
     // orden de los elementos en portada
     $order = \Goteo\Model\Home::getAll();
     // entradas de blog
     $posts_content = '';
     /*
                 if (isset($order['posts'])) {
        $home_posts = \Goteo\Model\Post::getList();
        if (!empty($home_posts)) {
     //                    $posts_content = '<div class="section-tit">'.Text::get('home-posts-header').'</div>';
            foreach ($posts as $id=>$title) {
                $the_post = \Goteo\Model\Post::get($id);
                $posts_content .= new View('view/email/newsletter_post.html.php', array('post'=>$the_post));
                break; // solo cogemos uno
            }
        }
                 }
     *
     */
     // Proyectos destacados
     $promotes_content = '';
     if (isset($order['promotes'])) {
         $home_promotes = \Goteo\Model\Promote::getAll(true, GOTEO_NODE, $lang);
         if (!empty($home_promotes)) {
             //                    $promotes_content = '<div class="section-tit">'.Text::get('home-promotes-header').'</div>';
             foreach ($home_promotes as $key => $promote) {
                 try {
                     $the_project = \Goteo\Model\Project::getMedium($promote->project, $lang);
                     $promotes_content .= new View('view/email/newsletter_project.html.php', array('promote' => $promote, 'project' => $the_project));
                 } catch (\Goteo\Core\Error $e) {
                     continue;
                 }
             }
         }
     }
     // capital riego
     $drops_content = '';
     /*
     if (isset($order['drops'])) {
         $calls     = \Goteo\Model\Call::getActive(3); // convocatorias en modalidad 1; inscripcion de proyectos
         $campaigns = \Goteo\Model\Call::getActive(4); // convocatorias en modalidad 2; repartiendo capital riego
     
         if (!empty($calls) || !empty($campaigns)) {
     //                    $drops_content = '<div class="section-tit">'.str_replace('<br />', ': ', Text::get('home-calls-header')).'</div>';
             // aqui lo del contenido dinamico
         }
     }
     */
     // montammos el contenido completo
     $tmpcontent = $content;
     foreach (\array_keys($order) as $item) {
         $var = $item . '_content';
         $tmpcontent .= ${$var};
     }
     return $tmpcontent;
 }
Example #7
0
 /**
  * Metodo para realizar una busqueda por parametros
  * @param array multiple $params 'category', 'location', 'reward'
  * @param bool showall si true, muestra tambien proyectos en estado de edicion y revision
  * @return array results
  */
 public static function params($params, $showall = false, $limit = null)
 {
     $results = array();
     $where = array();
     $values = array();
     if (!empty($params['category'])) {
         $where[] = 'AND id IN (
                                 SELECT distinct(project)
                                 FROM project_category
                                 WHERE category IN (' . implode(', ', $params['category']) . ')
                             )';
     }
     if (!empty($params['location'])) {
         $where[] = 'AND MD5(project_location) IN (' . implode(', ', $params['location']) . ')';
     }
     if (!empty($params['reward'])) {
         $where[] = 'AND id IN (
                                 SELECT DISTINCT(project)
                                 FROM reward
                                 WHERE icon IN (' . implode(', ', $params['reward']) . ')
                                 )';
     }
     if (!empty($params['query'])) {
         $where[] = ' AND (name LIKE :text
                             OR description LIKE :text
                             OR motivation LIKE :text
                             OR about LIKE :text
                             OR goal LIKE :text
                             OR related LIKE :text
                             OR keywords LIKE :text
                             OR location LIKE :text
                         )';
         $values[':text'] = "%{$params['query']}%";
     }
     if (!empty($params['node'])) {
         $where[] = ' AND node = :node';
         $values[':node'] = NODE_ID;
     }
     if (!empty($params['status'])) {
         $where[] = ' AND status = :status';
         $values[':status'] = $params['status'];
     }
     $minstatus = $showall ? '1' : '2';
     $maxstatus = $showall ? '4' : '7';
     $sql = "SELECT id\n                    FROM project\n                    WHERE status > {$minstatus}\n                    AND status < {$maxstatus}\n                    ";
     if (!empty($where)) {
         $sql .= implode(' ', $where);
     }
     $sql .= " ORDER BY status ASC, name ASC";
     // Limite
     if (!empty($limit) && \is_numeric($limit)) {
         $sql .= " LIMIT {$limit}";
     }
     try {
         $query = Model::query($sql, $values);
         foreach ($query->fetchAll(\PDO::FETCH_CLASS) as $match) {
             $results[] = Project::getMedium($match->id);
         }
         return $results;
     } catch (\PDOException $e) {
         throw new Exception('Fallo la sentencia de busqueda');
     }
 }
Example #8
0
 public function paid($id = null)
 {
     if ($_GET['result'] != 'ok') {
         die;
     }
     $id = $_GET['sendid'];
     if (empty($id)) {
         die;
     }
     // el aporte
     $invest = Model\Invest::get($id);
     if ($invest->status != "-1") {
         die;
     }
     $projectData = Model\Project::getMedium($invest->project);
     // para evitar las duplicaciones de feed y email
     if (isset($_SESSION['invest_' . $invest->id . '_completed'])) {
         die;
     }
     $user = Model\User::get($invest->user);
     // Paypal solo disponible si activado
     if ($invest->method == 'axes') {
         // hay que cambiarle el status a 0
         $invest->setStatus('0');
         // Evento Feed
         $log = new Feed();
         $log->setTarget($projectData->id);
         $log->populate('Aporte Axes', '/admin/invests', \vsprintf("%s ha aportado %s al proyecto %s mediante PayPal", array(Feed::item('user', $user->name, $user->id), Feed::item('money', $invest->amount . ' &yen;'), Feed::item('project', $projectData->name, $projectData->id))));
         $log->doAdmin('money');
         // evento público
         $log_html = Text::html('feed-invest', Feed::item('money', $invest->amount . ' &yen;'), Feed::item('project', $projectData->name, $projectData->id));
         if ($invest->anonymous) {
             $log->populate(Text::get('regular-anonymous'), '/user/profile/anonymous', $log_html, 1);
         } else {
             $log->populate($user->name, '/user/profile/' . $user->id, $log_html, $user->avatar->id);
         }
         $log->doPublic('community');
         unset($log);
     }
     // fin segun metodo
     // texto recompensa
     // @TODO quitar esta lacra de N recompensas porque ya es solo una recompensa siempre
     $rewards = $invest->rewards;
     array_walk($rewards, function (&$reward) {
         $reward = $reward->reward;
     });
     $txt_rewards = implode(', ', $rewards);
     // recaudado y porcentaje
     $amount = $projectData->invested;
     $percent = floor($projectData->invested / $projectData->mincost * 100);
     // email de agradecimiento al cofinanciador
     // primero monto el texto de recompensas
     //@TODO el concepto principal sería 'renuncia' (porque todos los aportes son donativos)
     if ($invest->resign) {
         // Plantilla de donativo segun la ronda
         if ($projectData->round == 2) {
             $template = Template::get(36);
             // en segunda ronda
         } else {
             $template = Template::get(28);
             // en primera ronda
         }
     } else {
         // plantilla de agradecimiento segun la ronda
         if ($projectData->round == 2) {
             $template = Template::get(34);
             // en segunda ronda
         } else {
             $template = Template::get(10);
             // en primera ronda
         }
     }
     // Dirección en el mail (y version para regalo)
     $txt_address = Text::get('invest-address-address-field') . ' ' . $invest->address->address;
     $txt_address .= '<br> ' . Text::get('invest-address-zipcode-field') . ' ' . $invest->address->zipcode;
     //            $txt_address .= '<br> ' . Text::get('invest-address-location-field') . ' ' . $invest->address->location;
     //            $txt_address .= '<br> ' . Text::get('invest-address-country-field') . ' ' . $invest->address->country;
     $txt_destaddr = $txt_address;
     $txt_address = Text::get('invest-mail_info-address') . '<br>' . $txt_address;
     // Agradecimiento al cofinanciador
     // Sustituimos los datos
     $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title);
     // En el contenido:
     $search = array('%USERNAME%', '%PROJECTNAME%', '%PROJECTURL%', '%AMOUNT%', '%REWARDS%', '%ADDRESS%');
     $replace = array($user->name, $projectData->name, SITE_URL . '/project/' . $projectData->id, $confirm->amount, $txt_rewards, $txt_address);
     $content = \str_replace($search, $replace, $template->text);
     $mailHandler = new Mail();
     $mailHandler->reply = GOTEO_CONTACT_MAIL;
     $mailHandler->replyName = GOTEO_MAIL_NAME;
     $mailHandler->to = $user->email;
     $mailHandler->toName = $user->name;
     $mailHandler->subject = $subject;
     $mailHandler->content = $content;
     $mailHandler->html = true;
     $mailHandler->template = $template->id;
     if ($mailHandler->send($errors)) {
         Message::Info(Text::get('project-invest-thanks_mail-success'));
     } else {
         Message::Error(Text::get('project-invest-thanks_mail-fail'));
         Message::Error(implode('<br />', $errors));
     }
     unset($mailHandler);
     // Notificación al autor
     $template = Template::get(29);
     // Sustituimos los datos
     $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title);
     // En el contenido:
     $search = array('%OWNERNAME%', '%USERNAME%', '%PROJECTNAME%', '%SITEURL%', '%AMOUNT%', '%MESSAGEURL%');
     $replace = array($projectData->user->name, $user->name, $projectData->name, SITE_URL, $invest->amount, SITE_URL . '/user/profile/' . $user->id . '/message');
     $content = \str_replace($search, $replace, $template->text);
     $mailHandler = new Mail();
     $mailHandler->to = $projectData->user->email;
     $mailHandler->toName = $projectData->user->name;
     $mailHandler->subject = $subject;
     $mailHandler->content = $content;
     $mailHandler->html = true;
     $mailHandler->template = $template->id;
     $mailHandler->send();
     unset($mailHandler);
     // marcar que ya se ha completado el proceso de aportar
     $_SESSION['invest_' . $invest->id . '_completed'] = true;
     // log
     Model\Invest::setDetail($invest->id, 'confirmed', 'El usuario regresó a /invest/confirmed');
 }