Example #1
0
 static function getData($id)
 {
     PDOSql::$pdobj = pdoConnect();
     $d = PDOSql::select("SELECT name, bg_image, subtitle FROM users WHERE id = ?", array($id));
     if (count($d) > 0) {
         $data['name'] = $d[0]['name'];
         $data['bg_image'] = $d[0]['bg_image'];
         $data['subtitle'] = $d[0]['subtitle'];
         return M::cr(true, $data);
     } else {
         return M::cr(false, array('user' => array()), 'No se encontraron datos del usuario');
     }
 }
Example #2
0
 public static function up2Web($img)
 {
     $msg = array();
     $fname = self::name(DATAROOT, 'up_', pathinfo($img['name']));
     $valid = self::validate($img, $fname);
     if (!$valid->success) {
         return M::cr(false, array(), $valid->msg);
     }
     // final move
     if (!move_uploaded_file($img['tmp_name'], DATAROOT . $fname)) {
         $msg[] = 'Failed to move uploaded file ' . $img['tmp_name'] . ' to ' . $fname;
     }
     // Check if $uploadOk is set to 0 by an error
     if (count($msg) > 0) {
         return M::cr(false, array(), implode(',', $msg));
     } else {
         return M::cr(true, array($fname));
     }
 }
Example #3
0
 public static function edit($data)
 {
     $p = array('title' => array('required' => true, 'type' => 'string', 'maxlength' => 140, 'label' => 'Titulo'), 'text' => array('required' => true, 'type' => 'string', 'label' => 'Texto'), 'image' => array('required' => false, 'type' => 'thumbnail', 'label' => 'Imagen'), 'tags' => array('required' => false, 'type' => 'string', 'label' => 'Tags'));
     $v = new Validator();
     $response = $v->validate($data, $p);
     if (!$response['success']) {
         return M::cr(false, $data, $response['msg']);
     }
     PDOSql::$pdobj = pdoConnect();
     if (isset($_FILES['image']['name'])) {
         $response = File::up2Web($_FILES['image']);
         if ($response->success) {
             // remove old image...
             if (isset($data['old_image'])) {
                 File::unlinkWeb($data['old_image']);
             }
             $image = $response->data[0];
         } else {
             return M::cr(false, $data, $response->msg);
         }
     } else {
         $image = '';
     }
     $params = array($data['title'], $data['text'], $image, $data['tags'], $data['id'], $_SESSION['userNAME']);
     $where = array(' id = ?', 'author = ?');
     $query = "UPDATE entries SET title = ?, text = ?, image = ?, tags = ? {%WHERE%}";
     PDOSql::update($query, $params, $where);
     return M::cr(true, array(), 'Se han actualizado los datos correctamente');
 }