public static function test_sqlite3_json_smartgrid($ofs, $sortby, $sortdir, $sorttype, $src = '')
 {
     //--
     $db = new SmartTestSQLite3Model();
     $model = $db->getConnection();
     //--
     //--
     $data = array();
     $data['status'] = 'OK';
     $data['crrOffset'] = (int) $ofs;
     $data['itemsPerPage'] = 25;
     $data['sortBy'] = (string) $sortby;
     $data['sortDir'] = (string) $sortdir;
     $data['sortType'] = (string) $sorttype;
     $data['filter'] = array('src' => (string) $src);
     //--
     if ((string) strtoupper((string) $sortdir) == 'DESC') {
         $syntax_sort_dir = 'DESC';
     } else {
         $syntax_sort_dir = 'ASC';
     }
     //end if else
     $syntax_sort_mode = '';
     switch ((string) $sortby) {
         case 'iso':
             $syntax_sort_mode = ' ORDER BY iso ' . $syntax_sort_dir;
             break;
         case 'name':
             $syntax_sort_mode = ' ORDER BY name ' . $syntax_sort_dir;
             break;
         case 'iso3':
             $syntax_sort_mode = ' ORDER BY iso3 ' . $syntax_sort_dir;
             break;
         case 'numcode':
             $syntax_sort_mode = ' ORDER BY numcode ' . $syntax_sort_dir;
             break;
         default:
             $syntax_sort_mode = '';
     }
     //end switch
     //--
     $where = '';
     if ((string) $src != '') {
         if (is_numeric($src)) {
             $where = $model->prepare_param_query(' WHERE numcode = ?', array((int) $src));
         } elseif (strlen((string) $src) == 2) {
             $where = $model->prepare_param_query(' WHERE iso = ?', array(SmartUnicode::str_toupper($src)));
         } elseif (strlen((string) $src) == 3) {
             $where = $model->prepare_param_query(' WHERE iso3 = ?', array(SmartUnicode::str_toupper($src)));
         } else {
             $where = $model->prepare_param_query(' WHERE name LIKE ?', array($src . '%'));
         }
         //end if else
     }
     //end if
     $data['totalRows'] = $model->count_data('SELECT COUNT(1) FROM sample_countries' . $where);
     $data['rowsList'] = $model->read_adata('SELECT iso, name, iso3, numcode FROM sample_countries' . $where . $syntax_sort_mode . ' LIMIT ' . (int) $data['itemsPerPage'] . ' OFFSET ' . (int) $data['crrOffset']);
     //--
     unset($db);
     // close
     //--
     //--
     return Smart::json_encode((array) $data);
     //--
 }
 private function _putcmd($cmd, $arg = '')
 {
     //--
     if ((string) $arg != '') {
         $cmd = $cmd . ' ' . $arg;
     }
     //end if
     //--
     if (!$this->_sock) {
         $this->_debug_print('ERROR: CMD command failed: ' . $cmd . "\n");
         return false;
     }
     //end if
     //--
     @fwrite($this->_sock, $cmd . "\r\n");
     //--
     if ($this->debug_level == 'full') {
         //--
         if (SmartUnicode::str_toupper(substr($cmd, 0, 5)) == 'PASS ') {
             $this->_debug_print('# ' . 'PASS ********' . "\n");
         } elseif (SmartUnicode::str_toupper(substr($cmd, 0, 6)) == 'ADMIN ') {
             $this->_debug_print('# ' . 'ADMIN ********' . "\n");
         } else {
             $this->_debug_print('# ' . $cmd . "\n");
         }
         //end if else
         //--
     }
     //end if
     //--
     return true;
     //--
 }
 public function add_attachment($message, $name = '', $ctype = '', $disp = 'attachment', $cid = '', $realattachment = 'no')
 {
     //--
     switch (strtolower($ctype)) {
         //-- text parts
         case 'text/plain':
         case 'text/html':
             //--
             if ((string) $disp != 'attachment') {
                 $disp = 'inline';
                 // default
             }
             //end if
             //--
             $encode = 'base64';
             // quoted-printable
             //--
             if ((string) $disp == 'inline') {
                 $charset = SmartUnicode::str_toupper(trim($this->charset));
             }
             //end if
             //--
             break;
             //-- email messages
         //-- email messages
         case 'message/rfc822':
         case 'message/partial':
         case 'partial/message':
             // fake type to avoid Google and Yahoo to show the Un-Encoded part
             //-- OLD method :: rewrite type to avoid conflicts (gmail, yahoo, thunderbird)
             //$ctype = 'partial/message';
             //$encode = 'base64';
             //$disp = 'attachment';
             //-- NEW Method (tested with Thunderbird and GMail)
             $ctype = 'message/rfc822';
             $encode = '7bit';
             // this is known to work with Thunderbird and GMail
             //$encode = 'base64'; this does not work with Thunderbird ...
             $disp = 'inline';
             //--
             $name = 'forwarded_message_' . date('YmdHis') . '_' . Smart::random_number(10000, 99999) . '.eml';
             $filename = $name;
             //--
             break;
             //-- the rest ...
         //-- the rest ...
         default:
             //--
             if ((string) $ctype == '') {
                 $ctype = 'application/octet-stream';
             }
             //end if
             //--
             $encode = 'base64';
             //--
             if ((string) $ctype == 'image' or (string) $ctype == 'image/jpeg' or (string) $ctype == 'image/jpg' or (string) $ctype == 'image/png' or (string) $ctype == 'image/gif') {
                 if ((string) $disp != 'inline') {
                     $disp = 'attachment';
                     // default
                 }
                 //end if
             } else {
                 $disp = 'attachment';
             }
             //end if else
             //--
             $filename = $name;
             //--
     }
     //end switch
     //--
     if ((string) $realattachment == 'yes') {
         // real attachments
         $this->atts[] = array('ctype' => $ctype, 'message' => $message, 'charset' => $charset, 'encode' => $encode, 'disp' => $disp, 'name' => $name, 'filename' => $filename, 'cid' => $cid);
     } else {
         $this->parts[] = array('ctype' => $ctype, 'message' => $message, 'charset' => $charset, 'encode' => $encode, 'disp' => $disp, 'name' => $name, 'filename' => $filename, 'cid' => $cid);
     }
     //end if else
     //--
 }