Esempio n. 1
0
 public function index($id, $width = 200, $height = 200, $crop = false)
 {
     if ($image = Model\Image::get($id)) {
         $image->display($width, $height, $crop);
     } else {
         throw new Error(Error::NOT_FOUND);
     }
 }
Esempio n. 2
0
 public static function process($action = 'list', $id = null)
 {
     $node = isset($_SESSION['admin_node']) ? $_SESSION['admin_node'] : \GOTEO_NODE;
     $model = 'Goteo\\Model\\Sponsor';
     $url = '/admin/sponsors';
     $errors = array();
     switch ($action) {
         case 'add':
             return new View('view/admin/index.html.php', array('folder' => 'base', 'file' => 'edit', 'data' => (object) array('order' => $model::next($node), 'node' => $node), 'form' => array('action' => "{$url}/edit/", 'submit' => array('name' => 'update', 'label' => Text::_('Añadir')), 'fields' => array('id' => array('label' => '', 'name' => 'id', 'type' => 'hidden'), 'node' => array('label' => '', 'name' => 'node', 'type' => 'hidden'), 'name' => array('label' => Text::_('Patrocinador'), 'name' => 'name', 'type' => 'text'), 'url' => array('label' => Text::_('Enlace'), 'name' => 'url', 'type' => 'text', 'properties' => 'size=100'), 'image' => array('label' => Text::_('Logo'), 'name' => 'image', 'type' => 'image'), 'order' => array('label' => Text::_('Posición'), 'name' => 'order', 'type' => 'text')))));
             break;
         case 'edit':
             // gestionar post
             if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                 // instancia
                 $item = new $model(array('id' => $_POST['id'], 'name' => $_POST['name'], 'node' => $_POST['node'], 'image' => $_POST['image'], 'url' => $_POST['url'], 'order' => $_POST['order']));
                 // tratar si quitan la imagen
                 $current = $_POST['image'];
                 // la actual
                 if (isset($_POST['image-' . $current . '-remove'])) {
                     $image = Model\Image::get($current);
                     $image->remove('sponsor');
                     $item->image = '';
                     $removed = true;
                 }
                 // tratar la imagen y ponerla en la propiedad image
                 if (!empty($_FILES['image']['name'])) {
                     $item->image = $_FILES['image'];
                 }
                 if ($item->save($errors)) {
                     Message::Info(Text::_('Datos grabados correctamente'));
                     throw new Redirection($url);
                 } else {
                     Message::Error(Text::_('No se ha grabado correctamente. ') . implode(', ', $errors));
                 }
             } else {
                 $item = $model::get($id);
             }
             return new View('view/admin/index.html.php', array('folder' => 'base', 'file' => 'edit', 'data' => $item, 'form' => array('action' => "{$url}/edit/{$id}", 'submit' => array('name' => 'update', 'label' => Text::get('regular-save')), 'fields' => array('id' => array('label' => '', 'name' => 'id', 'type' => 'hidden'), 'node' => array('label' => '', 'name' => 'node', 'type' => 'hidden'), 'name' => array('label' => Text::_('Patrocinador'), 'name' => 'name', 'type' => 'text'), 'url' => array('label' => Text::_('Enlace'), 'name' => 'url', 'type' => 'text', 'properties' => 'size=100'), 'image' => array('label' => Text::_('Logo'), 'name' => 'image', 'type' => 'image'), 'order' => array('label' => Text::_('Posición'), 'name' => 'order', 'type' => 'text')))));
             break;
         case 'up':
             $model::up($id, $node);
             throw new Redirection($url);
             break;
         case 'down':
             $model::down($id, $node);
             throw new Redirection($url);
             break;
         case 'remove':
             if ($model::delete($id)) {
                 Message::Info(Text::_('Se ha eliminado el registro'));
                 throw new Redirection($url);
             } else {
                 Message::Info(Text::_('No se ha podido eliminar el registro'));
             }
             break;
     }
     return new View('view/admin/index.html.php', array('folder' => 'base', 'file' => 'list', 'addbutton' => Text::_('Nuevo patrocinador'), 'data' => $model::getAll($node), 'columns' => array('edit' => '', 'name' => Text::_('Patrocinador'), 'url' => Text::_('Enlace'), 'image' => Text::_('Imagen'), 'order' => Text::_('Posición'), 'up' => '', 'down' => '', 'remove' => ''), 'url' => "{$url}"));
 }
Esempio n. 3
0
 public function save(&$errors = array())
 {
     if (!$this->validate($errors)) {
         return false;
     }
     // Primero la imagenImagen
     if (is_array($this->image) && !empty($this->image['name'])) {
         $image = new Image($this->image);
         if ($image->save($errors)) {
             $this->image = $image->id;
         } else {
             \Goteo\Library\Message::Error(Text::get('image-upload-fail') . implode(', ', $errors));
             $this->image = '';
         }
     }
     $fields = array('id', 'name', 'url', 'image', 'order');
     $set = '';
     $values = array();
     foreach ($fields as $field) {
         if ($set != '') {
             $set .= ", ";
         }
         $set .= "`{$field}` = :{$field} ";
         $values[":{$field}"] = $this->{$field};
     }
     try {
         $sql = "REPLACE INTO sponsor SET " . $set;
         self::query($sql, $values);
         if (empty($this->id)) {
             $this->id = self::insertId();
         }
         Check::reorder($this->id, 'up', 'sponsor');
         return true;
     } catch (\PDOException $e) {
         $errors[] = Text::_("No se ha guardado correctamente. ") . $e->getMessage();
         return false;
     }
 }
Esempio n. 4
0
 public static function getAll($position = 'home', $node = \GOTEO_NODE)
 {
     if (!in_array($position, array('home', 'footer'))) {
         $position = 'home';
     }
     $list = array();
     $values = array(':lang' => \LANG);
     if ($node == \GOTEO_NODE || empty($node)) {
         // portada goteo, sacamos todas las de blogs tipo nodo
         // que esten marcadas en la tabla post
         $sqlFilter = " WHERE post.{$position} = 1\n                    AND post.publish = 1\n                    ";
         $sqlField = "post.order as `order`,";
     } else {
         // portada nodo, igualmente las entradas de blogs tipo nodo
         // perosolo la que esten en la tabla de entradas en portada de ese nodo
         $sqlFilter = " WHERE post.id IN (SELECT post FROM post_node WHERE node = :node)\n                    AND post.publish = 1\n                    ";
         $values[':node'] = $node;
         $sqlField = "(SELECT `order` FROM post_node WHERE node = :node AND post = post.id) as `order`,";
     }
     $sql = "\n                SELECT\n                    post.id as id,\n                    post.blog as blog,\n                    IFNULL(post_lang.title, post.title) as title,\n                    IFNULL(post_lang.text, post.text) as `text`,\n                    post.image as `image`,\n                    post.media as `media`,\n                    {$sqlField}\n                    DATE_FORMAT(post.date, '%d-%m-%Y') as date,\n                    DATE_FORMAT(post.date, '%d | %m | %Y') as fecha,\n                    post.publish as publish,\n                    post.author as author,\n                    post.home as home,\n                    post.footer as footer,\n                    blog.type as owner_type,\n                    blog.owner as owner_id\n                FROM    post\n                INNER JOIN blog\n                    ON  blog.id = post.blog\n                LEFT JOIN post_lang\n                    ON  post_lang.id = post.id\n                    AND post_lang.lang = :lang\n                {$sqlFilter}\n                ORDER BY `order` ASC, title ASC\n                ";
     $query = static::query($sql, $values);
     foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $post) {
         // galeria
         $post->gallery = Image::getAll($post->id, 'post');
         $post->image = $post->gallery[0];
         $post->media = new Media($post->media);
         $post->type = $post->home == 1 ? 'home' : 'footer';
         // datos del autor
         switch ($post->owner_type) {
             case 'project':
                 $proj_blog = Project::getMini($post->owner_id);
                 $post->author = $proj_blog->owner;
                 $post->user = $proj_blog->user;
                 $post->owner_name = $proj_blog->name;
                 $sql = "UPDATE post SET author = '.{$proj_blog->owner}.' WHERE post.id = ?";
                 self::query($sql, array($post->id));
                 break;
             case 'node':
                 $post->user = User::getMini($post->author);
                 // (Nodesys)
                 break;
         }
         $list[$post->id] = $post;
     }
     return $list;
 }
Esempio n. 5
0
 *  along with Goteo.  If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */

use Goteo\Library\Text,
    Goteo\Model;

// aviso para el usuario, puede ser start->hola , ok->gracias o fail->lo sentimos

$user = $this['user'];
if (!$user instanceof Model\User) {
    $name = '';
    $avatarhtml = '';
} else {
    $name = $user->name . "さん";
    $avatar = ($user->avatar instanceof Model\Image) ? $user->avatar : Model\Image::get(1);
    $avatarhtml = '<img src="'.$avatar->getLink(50, 50, true).'" />';
}

switch ($this['message']) {
    case 'start':
        $title   = Text::get('regular-hello') . " $name";
//        $message = Text::get('project-invest-start');
        break;
    case 'login':
        $title   = Text::get('regular-hello') . " $name";
//        $message = Text::get('project-invest-login');
        break;
    case 'confirm':
        $title   = Text::get('regular-hello') . " $name";
//        $message = Text::get('project-invest-confirm');
Esempio n. 6
0
 public static function investors($project, $projNum = false, $showall = false)
 {
     $worth = array();
     $investors = array();
     $sql = "\n                SELECT\n                    invest.user as user,\n                    user.name as name,\n                    user.avatar as avatar,\n                    user.worth as worth,\n                    invest.amount as amount,\n                    DATE_FORMAT(invest.invested, '%d/%m/%Y') as date,\n                    ";
     $sql .= "user.hide as hide,\n                     invest.anonymous as anonymous\n                FROM    invest\n                INNER JOIN user\n                    ON  user.id = invest.user\n                WHERE   project = ?\n                AND     invest.status IN ('0', '1', '3', '4')\n                ORDER BY invest.invested DESC, invest.id DESC\n                ";
     $query = self::query($sql, array($project));
     foreach ($query->fetchAll(\PDO::FETCH_OBJ) as $investor) {
         $investor->avatar = Image::get($investor->avatar);
         if (empty($investor->avatar->id) || !$investor->avatar instanceof Image) {
             $investor->avatar = Image::get(1);
         }
         // si el usuario es hide o el aporte es anonymo, lo ponemos como el usuario anonymous (avatar 1)
         if (!$showall && ($investor->hide == 1 || $investor->anonymous == 1)) {
             // mantenemos la fecha del anonimo mas reciente
             $anonymous_date = empty($investors['anonymous']->date) ? $investor->date : $investors['anonymous']->date;
             $investors[] = (object) array('user' => 'anonymous', 'name' => Text::get('regular-anonymous'), 'projects' => null, 'avatar' => Image::get(1), 'worth' => $investor->worth, 'amount' => $investor->amount, 'date' => $investor->date);
         } else {
             if (!isset($worth[$investor->user])) {
                 $worth[$investor->user] = \Goteo\Model\User::calcWorth($investor->user);
             }
             $investors[] = (object) array('user' => $investor->user, 'name' => $investor->name, 'projects' => $investor->projects, 'avatar' => $investor->avatar, 'worth' => $worth[$investor->user], 'amount' => $investor->amount, 'date' => $investor->date);
         }
     }
     return $investors;
 }
Esempio n. 7
0
 public static function getMini($id)
 {
     try {
         $query = static::query("\r\n                    SELECT\r\n                        id,\r\n                        name,\r\n                        avatar,\r\n                        email,\r\n                        IFNULL(lang, 'es') as lang\r\n                    FROM user\r\n                    WHERE id = :id\r\n                    ", array(':id' => $id));
         $user = $query->fetchObject();
         // stdClass para qno grabar accidentalmente y machacar todo
         $user->avatar = Image::get($user->avatar);
         if (empty($user->avatar->id) || !$user->avatar instanceof Image) {
             $user->avatar = Image::get(1);
         }
         return $user;
     } catch (\PDOException $e) {
         return false;
     }
 }
Esempio n. 8
0
 public static function share($user, $category = null, $limit = null)
 {
     $array = array();
     try {
         $values = array(':me' => $user);
         $sql = "SELECT \n                            DISTINCT(user_interest.user) as id, \n                            user.name as name,\n                            user.avatar as avatar\n                        FROM user_interest\n                        INNER JOIN user_interest as mine\n                            ON user_interest.interest = mine.interest\n                            AND mine.user = :me\n                        INNER JOIN user\n                            ON  user.id = user_interest.user\n                            AND (user.hide = 0 OR user.hide IS NULL)\n                        WHERE user_interest.user != :me\n                        ";
         if (!empty($category)) {
             $sql .= "AND user_interest.interest = :interest\n                       ";
             $values[':interest'] = $category;
         }
         $sql .= " ORDER BY RAND()";
         if (!empty($limit)) {
             $sql .= " LIMIT {$limit}";
         }
         $query = static::query($sql, $values);
         $shares = $query->fetchAll(\PDO::FETCH_ASSOC);
         foreach ($shares as $share) {
             // nombre i avatar vienen en la sentencia, hay que sacar la imagen
             $share['user'] = $share['id'];
             $queryI = static::query("SELECT COUNT(DISTINCT(project)) FROM invest WHERE user = ? AND status IN ('0', '1', '3')", array($share['id']));
             $share['invests'] = $queryI->fetchColumn(0);
             $queryP = static::query('SELECT COUNT(id) FROM project WHERE owner = ? AND status > 2', array($share['id']));
             $share['projects'] = $queryP->fetchColumn(0);
             $share['avatar'] = empty($share['avatar']) ? Image::get(1) : Image::get($share['avatar']);
             if (!$share['avatar'] instanceof Image) {
                 $share['avatar'] = Image::get(1);
             }
             $array[] = (object) $share;
         }
         return $array;
     } catch (\PDOException $e) {
         throw new \Goteo\Core\Exception($e->getMessage());
     }
 }
Esempio n. 9
0
 public function save(&$errors = array())
 {
     if (!$this->validate($errors)) {
         return false;
     }
     $fields = array('id', 'title', 'text', 'legend', 'media');
     $values = array();
     foreach ($fields as $field) {
         if ($set != '') {
             $set .= ", ";
         }
         $set .= "`{$field}` = :{$field} ";
         $values[":{$field}"] = $this->{$field};
     }
     try {
         $sql = "REPLACE INTO glossary SET " . $set;
         self::query($sql, $values);
         if (empty($this->id)) {
             $this->id = self::insertId();
         }
         // Luego la imagen
         if (!empty($this->id) && is_array($this->image) && !empty($this->image['name'])) {
             $image = new Image($this->image);
             if ($image->save($errors)) {
                 $this->gallery[] = $image;
                 /**
                  * Guarda la relación NM en la tabla 'glossary_image'.
                  */
                 if (!empty($image->id)) {
                     self::query("REPLACE glossary_image (glossary, image) VALUES (:glossary, :image)", array(':glossary' => $this->id, ':image' => $image->id));
                 }
             } else {
                 Message::Error(Text::get('image-upload-fail') . implode(', ', $errors));
             }
         }
         return true;
     } catch (\PDOException $e) {
         $errors[] = Text::_("No se ha guardado correctamente. ") . $e->getMessage();
         return false;
     }
 }
Esempio n. 10
0
 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;
 }
Esempio n. 11
0
File: post.php Progetto: kenjs/Goteo
 public function save(&$errors = array())
 {
     if (empty($this->blog)) {
         return false;
     }
     $fields = array('id', 'blog', 'title', 'text', 'media', 'legend', 'date', 'allow', 'publish', 'home', 'footer', 'author');
     $values = array();
     foreach ($fields as $field) {
         if ($set != '') {
             $set .= ", ";
         }
         $set .= "`{$field}` = :{$field} ";
         $values[":{$field}"] = $this->{$field};
     }
     try {
         $sql = "REPLACE INTO post SET " . $set;
         self::query($sql, $values);
         if (empty($this->id)) {
             $this->id = self::insertId();
         }
         // Luego la imagen
         if (!empty($this->id) && is_array($this->image) && !empty($this->image['name'])) {
             $image = new Image($this->image);
             if ($image->save($errors)) {
                 $this->gallery[] = $image;
                 //                        $this->image = $image->id;
                 /**
                  * Guarda la relación NM en la tabla 'post_image'.
                  */
                 if (!empty($image->id)) {
                     self::query("REPLACE post_image (post, image) VALUES (:post, :image)", array(':post' => $this->id, ':image' => $image->id));
                 }
             } else {
                 Message::Error(Text::get('image-upload-fail') . implode(', ', $errors));
             }
         }
         // y los tags, si hay
         if (!empty($this->id) && is_array($this->tags)) {
             static::query('DELETE FROM post_tag WHERE post= ?', $this->id);
             foreach ($this->tags as $tag) {
                 $new = new Post\Tag(array('post' => $this->id, 'tag' => $tag));
                 $new->assign($errors);
                 unset($new);
             }
         }
         return true;
     } catch (\PDOException $e) {
         $errors[] = Text::_("No se ha guardado correctamente. ") . $e->getMessage();
         return false;
     }
 }
Esempio n. 12
0
 /**
  * Retorna les imatges i contingut en html
  *
  * $num_icons: el numero de icones per fila del widget
  * */
 public function html_content($num_icons = 19)
 {
     $URL = NODE_ID != GOTEO_NODE ? NODE_URL : SITE_URL;
     $ret = array();
     foreach ($this->avatars as $user => $mult) {
         $style = '';
         $w = $this->w_size;
         $h = $this->h_size;
         $src = $URL . '/image/2/' . "{$w}/{$h}";
         if ($this->investors[$user]->avatar instanceof \Goteo\Model\Image) {
             if ($this->investors[$user]->avatar->id == 1) {
                 $noface = \Goteo\Model\Image::get(2);
                 $src = $noface->getLink($w, $h, true);
             } else {
                 $src = $this->investors[$user]->avatar->getLink($w, $h, true);
             }
         }
         $img = '<a href="' . $URL . '/user/profile/' . $user . '"><img' . $style . ' src="' . $src . '" alt="' . $this->investors[$user]->name . '" title="' . $this->investors[$user]->name . '" /></a>';
         for ($i = 0; $i < $mult + 1; $i++) {
             $ret[] = $img;
             $total = count($ret);
             //cas que es posicioni a partir de la segona columna
             if ($num_icons > 14) {
                 //final de 1a fila, 2a columna
                 if (in_array($total, array($num_icons + 1, $num_icons * 2 - 12, $num_icons * 3 - 25))) {
                     $ret[] = '<div class="c"></div>';
                 }
                 if (in_array($total, array($num_icons * 5 - 38, $num_icons * 6 - 49, $num_icons * 7 - 60))) {
                     $ret[] = '<div class="a"></div>';
                 }
                 if (in_array($total, array($num_icons * 5 - 36, $num_icons * 6 - 47, $num_icons * 7 - 58))) {
                     $ret[] = '<div class="b"></div>';
                 }
                 if (in_array($total, array($num_icons * 9 - 71, $num_icons * 10 - 84))) {
                     $ret[] = '<div class="d"></div>';
                 }
             } else {
                 if ($total == $num_icons) {
                     $ret[] = '<div class="c"></div><div class="c"></div><div class="c"></div>';
                 }
                 if ($total == $num_icons * 2 + 1) {
                     $ret[] = '<div class="a"></div>';
                 }
                 if (in_array($total, array($num_icons * 2 + 3, $num_icons * 2 + 5))) {
                     $ret[] = '<div class="b"></div><div class="a"></div>';
                 }
                 if ($total == $num_icons * 2 + 7) {
                     $ret[] = '<div class="b"></div>';
                 }
                 if ($total == $num_icons * 3 + 8) {
                     $ret[] = '<div class="d"></div><div class="d"></div>';
                 }
             }
         }
     }
     return $ret;
     /*
     			//afegim el logo al final de tot
     			$final = array();
     			$total = count($ret);
     			$cols = floor(($total + 3*14 + 3*13 + 2*14)/$num_icons);
     
     			if($num_icons > 14) {
     				foreach($ret as $i => $v) {
     					if(in_array($i, array($num_icons*($cols-1) - 103,$num_icons*$cols - 107))) {
     						$final[] = '<div class="e"></div>';
     					}
     					$final[] = $v;
     				}
     			}
     			else {
     				foreach($ret as $i => $v) {
     					if(in_array($i, array($num_icons*($cols-2) - 94,$num_icons*($cols-1) - 98))) {
     					//if(in_array($i, array($num_icons*($cols-2) - 94))) {
     						$final[] = '<div class="e"></div>';
     					}
     					$final[] = $v;
     				}
     			}
     			return $final;
     */
 }
Esempio n. 13
0
 public function save(&$errors = array())
 {
     //            if (!$this->validate($errors)) return false;
     // Imagen de fondo de banner
     if (is_array($this->image) && !empty($this->image['name'])) {
         $image = new Image($this->image);
         if ($image->save()) {
             $this->image = $image->id;
         } else {
             \Goteo\Library\Message::Error(Text::get('image-upload-fail') . implode(', ', $errors));
             $this->image = '';
         }
     }
     $fields = array('id', 'node', 'title', 'description', 'url', 'project', 'image', 'order', 'active');
     $set = '';
     $values = array();
     foreach ($fields as $field) {
         if ($set != '') {
             $set .= ", ";
         }
         $set .= "`{$field}` = :{$field} ";
         $values[":{$field}"] = $this->{$field};
     }
     try {
         $sql = "REPLACE INTO banner SET " . $set;
         self::query($sql, $values);
         if (empty($this->id)) {
             $this->id = self::insertId();
         }
         return true;
     } catch (\PDOException $e) {
         $errors[] = Text::_("No se ha guardado correctamente. ") . $e->getMessage();
         return false;
     }
 }
Esempio n. 14
0
 public static function getGallery($id)
 {
     $gallery = array();
     try {
         $sql = "SELECT image FROM project_image WHERE project = ? AND (section = '' OR section IS NULL) ORDER BY `order` ASC, image DESC";
         $query = self::query($sql, array($id));
         foreach ($query->fetchAll(\PDO::FETCH_ASSOC) as $image) {
             $gallery[] = Model\Image::get($image['image']);
         }
         return $gallery;
     } catch (\PDOException $e) {
         return false;
     }
 }
Esempio n. 15
0
 /**
  * actualiza en la tabla los datos del proyecto
  * @param array $project->errors para guardar los errores de datos del formulario, los errores de proceso se guardan en $project->errors['process']
  */
 public function save(&$errors = array())
 {
     if ($this->dontsave) {
         return false;
     }
     if (!$this->validate($errors)) {
         return false;
     }
     try {
         // fail para pasar por todo antes de devolver false
         $fail = false;
         // los nif sin guiones, espacios ni puntos
         $this->contract_nif = str_replace(array('_', '.', ' ', '-', ',', ')', '('), '', $this->contract_nif);
         $this->entity_cif = str_replace(array('_', '.', ' ', '-', ',', ')', '('), '', $this->entity_cif);
         // Image
         if (is_array($this->image) && !empty($this->image['name'])) {
             $image = new Image($this->image);
             if ($image->save($errors)) {
                 $this->gallery[] = $image;
                 $this->image = $image->id;
                 /**
                  * Guarda la relación NM en la tabla 'project_image'.
                  */
                 if (!empty($image->id)) {
                     self::query("REPLACE project_image (project, image) VALUES (:project, :image)", array(':project' => $this->id, ':image' => $image->id));
                 }
             }
         }
         $fields = array('contract_name', 'contract_nif', 'contract_email', 'contract_entity', 'contract_birthdate', 'entity_office', 'entity_name', 'entity_cif', 'phone', 'address', 'zipcode', 'location', 'country', 'secondary_address', 'post_address', 'post_zipcode', 'post_location', 'post_country', 'name', 'subtitle', 'image', 'description', 'motivation', 'video', 'video_usubs', 'about', 'goal', 'related', 'reward', 'keywords', 'media', 'media_usubs', 'currently', 'project_location', 'scope', 'resource', 'comment', 'evaluation');
         $set = '';
         $values = array();
         foreach ($fields as $field) {
             if ($set != '') {
                 $set .= ', ';
             }
             $set .= "{$field} = :{$field}";
             $values[":{$field}"] = $this->{$field};
         }
         // Solamente marcamos updated cuando se envia a revision desde el superform o el admin
         //				$set .= ", updated = :updated";
         //				$values[':updated'] = date('Y-m-d');
         $values[':id'] = $this->id;
         $sql = "UPDATE project SET " . $set . " WHERE id = :id";
         if (!self::query($sql, $values)) {
             $errors[] = $sql . '<pre>' . print_r($values, 1) . '</pre>';
             $fail = true;
         }
         //                echo "$sql<br />";
         // y aquí todas las tablas relacionadas
         // cada una con sus save, sus new y sus remove
         // quitar las que tiene y no vienen
         // añadir las que vienen y no tiene
         //categorias
         $tiene = Project\Category::get($this->id);
         $viene = $this->categories;
         $quita = array_diff_assoc($tiene, $viene);
         $guarda = array_diff_assoc($viene, $tiene);
         foreach ($quita as $key => $item) {
             $category = new Project\Category(array('id' => $item, 'project' => $this->id));
             if (!$category->remove($errors)) {
                 $fail = true;
             }
         }
         foreach ($guarda as $key => $item) {
             if (!$item->save($errors)) {
                 $fail = true;
             }
         }
         // recuperamos las que le quedan si ha cambiado alguna
         if (!empty($quita) || !empty($guarda)) {
             $this->categories = Project\Category::get($this->id);
         }
         //skills
         $tiene = Project\Skill::get($this->id);
         $viene = $this->skills;
         $quita = array_diff_assoc($tiene, $viene);
         $guarda = array_diff_assoc($viene, $tiene);
         foreach ($quita as $key => $item) {
             $skill = new Project\Skill(array('id' => $item, 'project' => $this->id));
             if (!$skill->remove($errors)) {
                 $fail = true;
             }
         }
         foreach ($guarda as $key => $item) {
             if (!$item->save($errors)) {
                 $fail = true;
             }
         }
         // recuperamos las que le quedan si ha cambiado alguna
         if (!empty($quita) || !empty($guarda)) {
             $this->skills = Project\Skill::get($this->id);
         }
         //costes
         $tiene = Project\Cost::getAll($this->id);
         $viene = $this->costs;
         $quita = array_diff_key($tiene, $viene);
         $guarda = array_diff_key($viene, $tiene);
         foreach ($quita as $key => $item) {
             if (!$item->remove($errors)) {
                 $fail = true;
             } else {
                 unset($tiene[$key]);
             }
         }
         foreach ($guarda as $key => $item) {
             if (!$item->save($errors)) {
                 $fail = true;
             }
         }
         /* Ahora, los que tiene y vienen. Si el contenido es diferente, hay que guardarlo*/
         foreach ($tiene as $key => $row) {
             // a ver la diferencia con el que viene
             if ($row != $viene[$key]) {
                 if (!$viene[$key]->save($errors)) {
                     $fail = true;
                 }
             }
         }
         if (!empty($quita) || !empty($guarda)) {
             $this->costs = Project\Cost::getAll($this->id);
         }
         // recalculo de minmax
         $this->minmax();
         //retornos colectivos
         $tiene = Project\Reward::getAll($this->id, 'social');
         $viene = $this->social_rewards;
         $quita = array_diff_key($tiene, $viene);
         $guarda = array_diff_key($viene, $tiene);
         foreach ($quita as $key => $item) {
             if (!$item->remove($errors)) {
                 $fail = true;
             } else {
                 unset($tiene[$key]);
             }
         }
         foreach ($guarda as $key => $item) {
             if (!$item->save($errors)) {
                 $fail = true;
             }
         }
         /* Ahora, los que tiene y vienen. Si el contenido es diferente, hay que guardarlo*/
         foreach ($tiene as $key => $row) {
             // a ver la diferencia con el que viene
             if ($row != $viene[$key]) {
                 if (!$viene[$key]->save($errors)) {
                     $fail = true;
                 }
             }
         }
         if (!empty($quita) || !empty($guarda)) {
             $this->social_rewards = Project\Reward::getAll($this->id, 'social');
         }
         //recompenssas individuales
         $tiene = Project\Reward::getAll($this->id, 'individual');
         $viene = $this->individual_rewards;
         $quita = array_diff_key($tiene, $viene);
         $guarda = array_diff_key($viene, $tiene);
         foreach ($quita as $key => $item) {
             if (!$item->remove($errors)) {
                 $fail = true;
             } else {
                 unset($tiene[$key]);
             }
         }
         foreach ($guarda as $key => $item) {
             if (!$item->save($errors)) {
                 $fail = true;
             }
         }
         /* Ahora, los que tiene y vienen. Si el contenido es diferente, hay que guardarlo*/
         foreach ($tiene as $key => $row) {
             // a ver la diferencia con el que viene
             if ($row != $viene[$key]) {
                 if (!$viene[$key]->save($errors)) {
                     $fail = true;
                 }
             }
         }
         if (!empty($quita) || !empty($guarda)) {
             $this->individual_rewards = Project\Reward::getAll($this->id, 'individual');
         }
         // colaboraciones
         $tiene = Project\Support::getAll($this->id);
         $viene = $this->supports;
         $quita = array_diff_key($tiene, $viene);
         // quitar los que tiene y no viene
         $guarda = array_diff_key($viene, $tiene);
         // añadir los que viene y no tiene
         foreach ($quita as $key => $item) {
             if (!$item->remove($errors)) {
                 $fail = true;
             } else {
                 unset($tiene[$key]);
             }
         }
         foreach ($guarda as $key => $item) {
             if (!$item->save($errors)) {
                 $fail = true;
             }
         }
         /* Ahora, los que tiene y vienen. Si el contenido es diferente, hay que guardarlo*/
         foreach ($tiene as $key => $row) {
             // a ver la diferencia con el que viene
             if ($row != $viene[$key]) {
                 if (!$viene[$key]->save($errors)) {
                     $fail = true;
                 }
             }
         }
         if (!empty($quita) || !empty($guarda)) {
             $this->supports = Project\Support::getAll($this->id);
         }
         //listo
         return !$fail;
     } catch (\PDOException $e) {
         $errors[] = Text::_('No se ha grabado correctamente. ') . $e->getMessage();
         //Text::get('save-project-fail');
         return false;
     }
 }