Explorar el Código

Refactoring renaming method ".empty" to ".isempty", fix one of sql queries on orders.

mingodad hace 11 años
padre
commit
ec74da80f2

+ 6 - 6
SquiLu-ourbiz/happyhttp.nut

@@ -134,7 +134,7 @@ class HappyHttpConnection {
 	// Update the connection (non-blocking)
 	// Just keep calling this regularly to service outstanding requests.
 	function pump(milisec=10) { //10 miliseconds to prevent high cpu load
-		if( m_Outstanding.empty() ) return;		// no requests outstanding
+		if( m_Outstanding.isempty() ) return;		// no requests outstanding
 		assert( m_Sock != null );	// outstanding requests but no connection!
 
 		if( !datawaiting( m_Sock, milisec) ) return;	// recv will block
@@ -162,7 +162,7 @@ class HappyHttpConnection {
 		else
 		{
 			local used = 0;
-			while( used < a && !m_Outstanding.empty() )
+			while( used < a && !m_Outstanding.isempty() )
 			{
 				local r = m_Outstanding[0];
 				local u = r->pump( buf, used, a-used );
@@ -181,7 +181,7 @@ class HappyHttpConnection {
 	}
 
 	// any requests still outstanding?
-	function outstanding() { return m_Outstanding && !m_Outstanding.empty(); }
+	function outstanding() { return m_Outstanding && !m_Outstanding.isempty(); }
 
 	// ---------------------------
 	// high-level request interface
@@ -436,7 +436,7 @@ class HappyHttpResponse {
 	}
 	
 	function FlushHeader(){
-		if( m_HeaderAccum.empty() ) return;	// no flushing required
+		if( m_HeaderAccum.isempty() ) return;	// no flushing required
 		local rc = m_HeaderAccum.match("([^:]+):%s*(.+)");
 		if(!rc) throw(format("Invalid header (%s)", m_HeaderAccum));
 		m_Headers[ rc[0].tolower() ] <- rc[1];
@@ -464,7 +464,7 @@ class HappyHttpResponse {
 	}
 	
 	function ProcessHeaderLine( line ){
-		if( line.empty() )
+		if( line.isempty() )
 		{
 			FlushHeader();
 			// end of headers
@@ -493,7 +493,7 @@ class HappyHttpResponse {
 	function ProcessTrailerLine(line){
 		// TODO: handle trailers?
 		// (python httplib doesn't seem to!)
-		if( line.empty() ) Finish();
+		if( line.isempty() ) Finish();
 		// just ignore all the trailers...
 	}
 	

+ 1 - 1
SquiLu-ourbiz/help-view.nut

@@ -129,7 +129,7 @@ class OurHelpWindow extends HelpWindow
 
 	function on_navigate(sender, udata){
 		this = sender->window();
-		if(sender == btnBackward && !_navigation.empty() )
+		if(sender == btnBackward && !_navigation.isempty() )
 		{
 			view_html->topline(_navigation.top());
 			_navigation.pop();

+ 13 - 9
SquiLu-ourbiz/ourbiz.nut

@@ -1391,18 +1391,21 @@ local function orders_sql_search_list(qs_tbl, post_tbl){
 		else if (search_str && search_str.len() > 0) {
 			if (so.products){
 				mf.write(" and o.id in ( select order_id from orders_lines where ",
-					" description like "" , search_str , "" order by id desc limit " , so.query_limit , ")");
+					" description like '" , search_str , "' order by id desc limit " , so.query_limit , ")");
 			}
-			else mf.write(" and ");
+			else
+			{
+				mf.write(" and ");
 
-			if (so.notes) mf.write(" o.notes ");
-			else if (so.date) mf.write(" o.order_date ");
-			//lo_search_str = escapeSqlLikeSearchStr(dbDate(search_str))
-			//table.insert(sql, " and order_date = (("")
-			else if (so.total) mf.write(" o.total_amt ");
-			else  mf.write(" o.entity_name ");
+				if (so.notes) mf.write(" o.notes ");
+				else if (so.date) mf.write(" o.order_date ");
+				//lo_search_str = escapeSqlLikeSearchStr(dbDate(search_str))
+				//table.insert(sql, " and order_date = (("")
+				else if (so.total) mf.write(" o.total_amt ");
+				else  mf.write(" o.entity_name ");
 
-			mf.write(" like '" , search_str , "' ");
+				mf.write(" like '" , search_str , "' ");
+			}
 		}
 	}
 
@@ -3157,6 +3160,7 @@ Content-Length: %d
 		}
 
 		if (sql){
+			debug_print(sql, "\n", db.errmsg(), "\n")
 			local stmt = db.prepare(sql);
 			//debug_print(sql, "\n", db.errmsg(), "\n")
 			data = stmt.asSleArray();

+ 3 - 3
SquiLu-ourbiz/pdf-order.nut

@@ -90,7 +90,7 @@ class PDF_Order extends Sq_Fpdf
 	}
 
 	function getLogo(){
-		if(!logoFileName || logoFileName.empty()){
+		if(!logoFileName || logoFileName.isempty()){
 			logoFileName = "dadbiz_120.png";
 		}
 		return logoFileName;
@@ -98,7 +98,7 @@ class PDF_Order extends Sq_Fpdf
 
 	function logoImage(px, py, pwidth){
 		local logoImg = getLogo();
-		if(!logoImg.empty()) Image(logoImg, px, py, pwidth);
+		if(!logoImg.isempty()) Image(logoImg, px, py, pwidth);
 	}
 
 	function orderTable(lineCount)
@@ -261,7 +261,7 @@ class PDF_Order extends Sq_Fpdf
 				x++;
 			}
 
-			if(!water_mark.empty()){
+			if(!water_mark.isempty()){
 				SetAlpha(0.7, "Darken");
 				//SetAlpha(0.5);
 				SetFont("Arial","B",50);

+ 245 - 0
SquiLu-ourbiz/sq-server-plugin.nut

@@ -8,12 +8,186 @@ local globals = getroottable();
 if(!globals.rawget("APP_CODE_FOLDER", false)) ::APP_CODE_FOLDER <- ".";
 WIN32 <- os.getenv("WINDIR") != null;
 
+math.srand(os.time());
+
 //local AT_DEV_DBG=true;
 
 //local APP_CODE_FOLDER = sqfs.currentdir();
 //local EDIT_MD5_PASSWORD = md5("edit_user:r.dadbiz.es:okdoedit");
 //local VIEW_MD5_PASSWORD = md5("view_user:r.dadbiz.es:okdoview");
 
+class MySMTP  {
+	boundary = null;
+	smtp_server = null;
+	smtp_port = null;
+	smtp_user_name = null;
+	smtp_user_passw = null;
+	smtp_from = null;
+	smtp_to = null;
+	smtp_subject = null;
+	smtp_message = null;
+	attachments = null;
+	_ssl = null;
+	_quite = null;
+	_fout = null;
+	
+	constructor(smtp, port){
+		server(smtp, port);
+		attachments = [];
+		_quite = false;
+	}
+	function server(smtp, port) {
+		smtp_server = smtp; 
+		smtp_port = port;
+		boundary = "_=_+-mixed-+19JK4720AB04PX483";
+		_fout = file("MySMPT.log", "wb");
+	}
+	function login(user, passw) {
+		smtp_user_name = user;
+		smtp_user_passw = passw;
+	}
+	function from(pfrom) {smtp_from = pfrom;}
+	function to(pto) {smtp_to = pto; }
+	function subject(psubject) {smtp_subject = psubject; }
+	function message(pmessage) {smtp_message = pmessage; }
+	function attach(fn, mime) {
+		attachments.push([fn, mime]);
+	}
+	function _write(str){
+		_ssl.write(str);
+		_fout.write(str);
+	}
+	function _read_line(expected_code){
+		local result;
+		while (true){
+			result = _ssl.read();
+			if(type(result) == "integer"){
+				if (result < 0){ 
+					throw(axtls.get_error(result));
+				}
+			}
+			if(type(result) == "string"){
+				//print(result);
+				local response_code;
+				result.gmatch("^(%d+)", function(m){
+						response_code = m.tointeger();
+						return false;
+					});
+				//print("Code check", expected_code, response_code);
+				if(!response_code || (expected_code != response_code)){
+					throw(format("Response code '%d' not equal to expected '%d'", 
+						response_code, expected_code));
+				}
+				return true;
+			}
+			os.sleep(10);
+		}
+	}
+	function _write_line(line){
+		local end_line = "\r\n";
+		local result = _write(line);
+		_write(end_line);
+		return result;
+	}
+	function _write_message(msg){
+		local end_msg = "\r\n.\r\n";
+		local result = _write(msg);
+		_write(end_msg);
+		return result;
+	}
+	function _getAttachemt(fn){
+		local fd = file(fn, "rb");
+		local fc = fd.read(fd.len());
+		fd.close();
+		return base64.encode(fc);
+	}
+	function send(){
+		local client_sock = socket.tcp();
+		client_sock.connect(smtp_server, smtp_port);
+
+		local options = axtls.SSL_SERVER_VERIFY_LATER;
+		local ssl_ctx = axtls.ssl_ctx(options, axtls.SSL_DEFAULT_CLNT_SESS);
+
+		_ssl = ssl_ctx.client_new(client_sock.getfd());
+		// check the return status
+		local res = _ssl.handshake_status();
+		if (res != axtls.SSL_OK) throw( axtls.get_error(res));
+		
+		_read_line(220);
+		_write_line("ehlo " + smtp_user_name);
+		_read_line(250);
+		local credentials = base64.encode(format("\x00%s\x00%s", 
+			smtp_user_name, smtp_user_passw));
+		//print("credentials", credentials);
+		_write_line(format("AUTH PLAIN %s", credentials));
+		_read_line(235);
+		_write_line(format("mail from: <%s>", smtp_from || smtp_user_name));
+		_read_line(250);
+		_write_line(format("rcpt to: <%s>", smtp_to));
+		_read_line(250);
+		_write_line("data");
+		_read_line(354);
+
+		local buf = format([==[
+From: Tais Alvarez <%s>
+To: Domingo <%s>
+Subject: %s
+]==], smtp_from || smtp_user_name, smtp_to, smtp_subject);
+		_write(buf);
+		local hasAttachment = attachments.len() > 0;
+		if (hasAttachment){
+			buf = format([==[
+Content-Type: multipart/mixed; boundary="%s"
+
+--%s
+Content-Type: text/plain; charset="utf-8" 
+Content-Transfer-Encoding: 8bit
+]==], boundary, boundary);
+			_write(buf);
+		}
+		buf = format([==[
+
+%s
+%s
+]==], os.date(), smtp_message);
+		_write(buf);
+		if (hasAttachment){
+			foreach( k,v in attachments) {
+				buf = format([==[
+--%s
+Content-Type: %s; name="%s" 
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment
+
+%s
+]==], boundary, v[1], v[0], _getAttachemt(v[0]));
+				_write(buf);
+			}
+			buf = format("--%s--", boundary);
+			_write(buf);
+		}
+		_write_message("");
+		//print("Done !");
+		_read_line(250);
+		_write_line("quit");
+		_read_line(221);
+		_ssl.free();
+		ssl_ctx.free();
+		client_sock.close();
+	}
+}
+
+function IntToDottedIP( intip )
+{
+	local octet = [0,0,0,0];
+	for(local i=3; i >= 0; --i)
+	{
+		octet[i] = (intip & 0xFF).tostring();
+		intip = intip >> 8;
+	}
+	return octet.concat(".");
+}
+
 if(!globals.rawget("gmFile", false)) ::gmFile <- blob();
 if(!globals.rawget("__tplCache", false)) ::__tplCache <- {};
 
@@ -116,6 +290,73 @@ function var2json(v){
 	return "";
 }
 
+function json2var(json) {
+	local vm = SlaveVM();
+	local slave_func = "getTable";
+	
+	//debug_print(json, "\n");
+	//convert new data from json to squilu table for merge
+	vm.compilestring(slave_func, "return " + json);
+	local tbl = vm.call(true, slave_func);
+	return tbl;
+}
+
+function doSaveTableArrayToFD(ta, fd){
+	local function dumpValue(val){
+		local vtype = type(val);
+		if(vtype == "string") fd.write(format("%q,\n", val));
+		else if(vtype == "integer") fd.write(format("%d,\n", val));
+		else if(vtype == "float") fd.write(format("%f,\n", val));
+		else if(vtype == "bool") fd.write(format("%s,\n", val ? "true" : "false"));
+		else if(vtype == "null") fd.write("null,\n");
+		else throw format("Only string, integer, float, bool are supported ! (%s)", vtype);
+	}
+	local tatype = type(ta);
+	if(tatype == "table"){
+		fd.write(format("{\n"));
+		foreach(k,v in ta){
+			fd.write(format("[%q] = ", k));
+			local vtype = type(v);
+			if(vtype == "table" || vtype == "array"){
+				doSaveTableArrayToFD(v, fd);
+			}
+			else
+			{
+				dumpValue(v);
+			}
+		}
+		fd.write(format("},\n"));
+	}
+	else if(tatype == "array"){
+		fd.write(format("[\n"));		
+		foreach(k,v in ta){
+			local vtype = type(v);
+			if(vtype == "table" || vtype == "array"){
+				doSaveTableArrayToFD(v, fd);
+			}
+			else
+			{
+				dumpValue(v);
+			}
+		}
+		fd.write(format("],\n"));		
+	}
+	else throw "Only table/array suported";
+}
+
+function doSaveTableArrayToFileName(tbl, fname){
+	local fd = file(fname, "w");
+	fd.write("return [\n");
+	doSaveTableArrayToFD(tbl, fd);
+	fd.write("];");
+	fd.close();
+}
+
+function doLoadTableArrayFromFileName(fname){
+	local func = loadfile(fname);
+	return func()[0];
+}
+
 function fillTemplate(template, data, nocache){
 	data.escapeHtml <- escapeHtml;
 	local mixFunc =getTemplate(template, nocache);
@@ -571,6 +812,10 @@ if(AT_DEV_DBG || !globals.rawget("MyOurBizLoaded", false)) {
 	dofile(APP_CODE_FOLDER + "/ourbiz.nut");
 }
 
+if(AT_DEV_DBG || !globals.rawget("MyOurShoppingCartLoaded", false)) {
+	dofile(APP_CODE_FOLDER + "/ourbiz-shopping-cart.nut");
+}
+
 local ourbiz_password = md5("mingote:ourbiz.dadbiz.es:tr14pink");
 function handle_request(request){
 	//static content served by mongoose directly