2021年11月19日 星期五

CodeCharge 搭配 CloudFlare經常沒用多久就自動被登出?!

 經過研究發現是 CodeChargeStudio 的 Common.php中有這一行:

if (session_id() == "") { session_start(); }

if (CCGetUserAddr() != $_SERVER["REMOTE_ADDR"]) { CCLogoutUser(); }

也就是 CCS 會檢查 REMOTE_ADDR,如果不一樣就會被強制登出!

解決這個問題,就必須拿掉這一行檢查。




//Initialize Common Variables @0-8AF2F782
$PHPVersion = explode(".",  phpversion());
if (($PHPVersion[0] < 4) || ($PHPVersion[0] == 4  && $PHPVersion[1] < 1)) {
    echo "Sorry. This program requires PHP 4.1 and above to run. You may upgrade your php at <a href='http://www.php.net/downloads.php'>http://www.php.net/downloads.php</a>";
    exit;
}
if (session_id() == "") { session_start(); }
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
  $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
// if (CCGetUserAddr() != $_SERVER["REMOTE_ADDR"]) { CCLogoutUser(); }

2021年10月24日 星期日

CodeCharge Studio 的 子網頁裡面的 Panel 的參照

一個子網頁(被 include 的子網頁),它裡面的 Panel ,要被參照,例如 visible

應該這樣用:

global $page;

$page->control->Visible = false;

$page->panel->Visible = false;


不可以這樣:

global $panel;

$panel->Visible = true;


這個問題,我經常弄錯,紀錄在這裡,提醒自己。


但是,如果是子網頁page -> 子網頁subpage -> Panel 

就不能再這樣用了!

function subpage_BeforeShow(& $sender)

global $subpage;

$subpage->control->Visible = false;

$subpage->panel->Visible = false;



比較困擾的應該是因為 Panel 是透明的,無法直接用 global $Panel1;這種方式

此時,只能使用 $Component 這個變數了!

例如:

function navside_BeforeShow(& $sender)

{

    $navside_BeforeShow = true;

    $Component = & $sender;

    $Container = & CCGetParentContainer($sender);

    global $navside; //Compatibility

//End navside_BeforeShow


//Custom Code @17-2A29BDB7

// -------------------------

    // Write your own code here.

    

           $db = new clsDBconn_mysql();

$SQL = "SELECT is_fund_opened(".

             $db->ToSQL($_SESSION["UserID"], ccsInteger) .

             ") as v_opened;";

$sql_log = "CALL system_log(".$db->ToSQL($SQL, ccsText).")";

$db->query($sql_log);

$db->query($SQL);

$result = $db->next_record();

if ($db->f("v_opened")==0) {

    $Component->Panel1->Visible = True;

    $Component->Panel2->Visible = False;

} else {

    $Component->Panel1->Visible = False;

    $Component->Panel2->Visible = True;

}


    

    $db->close();

    

    

// -------------------------

//End Custom Code


//Close navside_BeforeShow @1-E75A1C39

    return $navside_BeforeShow;

}


這一段 CCS 自己的說明,要好好看看:

Referencing Objects

The objects in the Web applications generated by CodeCharge Studio can be referenced in a variety of ways. In many cases, to work with a specific object within a program you will need to know its position within the program hierarchy. For example, an object that is placed directly on the page may need to be addressed differently compared to an object placed within a form (which is also an object).

ASP

Examples of working with objects Syntax
Form object placed on a page Page Events <form>.Visible = False
Form Events EventCaller.Visible = False
Control object placed within a form Page Events <form>.<control>.Value = "123"
Form Events EventCaller.<control>.Value = "123"
Control Events EventCaller.Value = "123"
Control object placed on a page Page Events <control>.Value = "ABC"
Control Events EventCaller.Value = "ABC"
Control object placed on an included page Main Page Events <page>.<control>.Visible = False
Includable Page Events EventCaller.<control>.Visible = False
Control Events EventCaller.Visible = False
Form object placed on an included page Main Page Events <page>.<form>.Visible = False
Includable Page Events EventCaller.<form>.Visible = False
Form Events EventCaller.Visible = False
Control object placed in a form within an  included page  Main Page Events <page>.<form>.<control>.Visible = False
Includable Page Events EventCaller.<form>.<control>.Visible = False
Form Events EventCaller.<control>.Visible = False
Control Events EventCaller.Visible = False

Note: Using EventCaller is recommended when planning to reuse the event code since it doesn't require referring to objects by name.

Perl

Examples of working with objects Syntax
Form object placed on a page $<form>->{Visible} = 0;
Control object placed within a form $<form>->{<control>}->SetValue("123");
Control object placed on a page $<control>->SetValue("ABC");
Control object placed on an included page $<page>->{<control>}->{Visible} = 0;
Form object placed on an included page $<page>->{<form>}->{Visible} = 0;
Control object placed in a form within an included page  $<page>->{<form>}->{<control>}->{Visible} = 0;
Assigning an object to a variable $<variable> = $<object>;

Java

Examples of working with objects Syntax
Form object placed on a page Page Events e.getPage().getComponent("<form>").setVisible(false);
Form Events e.getComponent().setVisible(false);
Control object placed within a form Page Events e.getPage().getComponent("<form>").getControl("<control>").setValue("123");
Form Events e.getComponent().getControl("<control>").setValue("123");
Control Events e.getControl().setValue("123");
Control object placed on a page Page Events e.getPage().getControl("<control>").setValue("ABC");
Control Events e.getControl().setValue("ABC");
Assigning an object to a variable <variable> = <object>;

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

C#

Examples of working with objects Syntax
Form object placed on a page Grid and Editable Grid Events <form>Repeater.Visible = false;
Record Events <form>Holder.Visible = false;
Directory and Path Events <form>.Visible = false;
Control object placed within a Record form <form><control>.Visible = false;
Control object placed within a Grid, Editable Grid, Directory and Path form Control's Before Show Event <form><control>.Visible = false;
Form's Before Show and Before Show Row Event Object reference should be retrieved from the FormControls collection.
See the ItemDataBound Event MSDN example.
Control object placed on a page <control>.Visible = false;
Assigning an object to a variable <variable> = <object>;

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

VB.Net

Examples of working with objects Syntax
Form object placed on a page Grid and Editable Grid Events <form>Repeater.Visible = False
Record Events <form>Holder.Visible = False
Directory and Path Events <form>.Visible = False
Control object placed within a Record form <form><control>.Visible = False
Control object placed within a Grid, Editable Grid, Directory and Path form Control's Before Show Event <form><control>.Visible = False
Form's Before Show and Before Show Row Event Object reference should be retrieved from the FormControls collection.
See the ItemDataBound Event MSDN example.
Control object placed on a page <control>.Visible = False
Assigning an object to a variable <variable> = <object>

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

ColdFusion

Examples of working with objects Syntax
Form variable placed on a page or within a form <CFSET blnReadAllowed<form>=false>
Control variable placed within a form or a page <CFSET fld<control> = "abc">

Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above.

PHP

When using PHP you can address objects in a generic way as $Component to refer to the component raising the event, and $Container to refer to the host form of $Component. This method of referring to objects is recommended to make the event code reusable since it doesn't require referring to objects by name. You can also refer to objects using global variables, for example use $MyGrid to refer to 'MyGrid' grid.

Examples of working with objects in a generic way Syntax
Form object placed on a page Page Events $Component->form->visible = false;
Form Events $Component->Visible = false;
Control object placed within a form Page Events $Component->form->control->SetValue($Component->form->PageNumber);
Form Events $Component->control->SetValue($Component->PageNumber);
Control Events $Component->SetValue($Container->PageNumber);
Control object placed on a page Page Events $Component->control->SetValue("ABC");
Control Events $Component->SetValue("ABC");
Control object placed on an included page Main Page Events $Component->page->control->Visible = false;
Includable Page  Events $Component->control->Visible = false;
Control Events $Component->Visible = false;
Form object placed on an included page Main Page Events $Component->page->form->Visible = false;
Includable Page  Events $Component->form->Visible = false;
Form Events $Component->Visible = false;
Control object placed in a form within an  included page  Main Page Events $Component->page->form->control->Visible = false;
Includable Page  Events $Component->form->control->Visible = false;
Form Events $Component->control->Visible = false;
Control Events $Component->Visible = false;


Examples of working with objects using global variables Syntax
Form object placed on a page $form->Visible = false;
Control object placed within a form $form->control->SetValue("123");
Control object placed on a page $control->SetValue("ABC");
Control object placed on an included page $page->control->Visible = false;
Form object placed on an included page $page->form->Visible = false;
Control object placed in a form within an  included page  $page->form->control->Visible = false;



2021年6月16日 星期三

MYSQL: IF NOT EXIST () THEN ..... END IF;

 IF not exists (SELECT * FROM funit WHERE fu_id = in_myfu_id) THEN

ROLLBACK;

SET out_ret_code = CONCAT("ERROR: 操作人經營單位不存在資料庫中!",in_myfu_id);

CALL system_log(out_ret_code);

LEAVE proc_label;

END IF;

2021年5月15日 星期六

Bootstrap 5 的 iframe Embeded Youtube 影片做法改變了

https://getbootstrap.com/docs/5.0/helpers/ratio/#example 



<div class="ratio ratio-16x9">

  <iframe src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" title="YouTube video" allowfullscreen></iframe>

</div>

2021年4月23日 星期五

ScriptCase 複雜的 SQL Builder出來的資料集,可能導致翻頁錯誤

如題。

使用 ScriptCase Grid 建立新的 Application 時,如果使用 SQL Builder,如果是較複雜的 SQL Stmt,導致可能產生 Grid 顯示時,Page Up/Down翻頁程式有錯誤。

此時,只要將該 SQL Stmt 改成 建立 view 的方式,再來做成 Grid Application ,這樣就正常了!


2021年4月9日 星期五

ScriptCase 的按鈕 php 與 Ajax 有何不同

 ScriptCase 的表單Form,有按鈕功能。

按鈕有四種型態:PHP/JAVASCRIPT/AJAX/LINK

如果僅是更新資料庫欄位裡面的值,使用AJAX  PHP,就可以了。最快、簡便。

例如:

{confirmed} = 1;

{confirmed_dt} = date("Y-m-d H-i-s");

這是更新該筆資料紀錄裡面的兩個欄位值:Confirmed確認值為1、confirmed_dt 日期為當時日期。


如果一樣的程式碼,改成 PHP,那麼執行起來,就不一樣了。變成執行完程式,就離開這個Application!也沒有自動存檔,所以,這樣處理是不對的。


--------------------------------------------------------------------------

1. 在 Programming -> JavaScript Methods -> New Method

建立一個新的 Method,內容只有一行:

nm_atualiza ('alterar');

Name 例如為: jssave

這是SC本身執行 SAVE(或 UPDATE)的 JavaScript Code。


2. 建立一個 Ajax Button

程式碼:

{confirmed} = 1;

{confirmed_dt} = date("Y-m-d H-i-s");

sc_ajax_javascript('jssave', array());

{confirmed}、{confirmed_dt}這是兩個要改變內容值的欄位。

SCriptcase 放置按鈕在FORM/GRID隨意的位置

將按鈕放置在 Scriptcase Form / Grid的任意位置

就 Scriptcase 而言,設計一個按鈕放在表頭、或是表尾,是一件非常簡單的事情。

但有時候,會希望將按鈕放在距離特定資料附近的位置,這樣比較直觀。

It’s easy to create a button on the top or bottom of a Scriptcase form or Grid application (as element of the toolbar).

But sometime you might need buttoms directly near certain elements within the form (or within the line of a grid).

1. Create a link for the action (if you click on the button)

One of the easiest ways is to use the Scriptcase macro:

sc_make_link(Application, Parameters)

example:

$string_link = sc_make_link(grid_images, ref_object_type='contact';ref_object_id={id});

The generates a string with the link to the Grid-application ‘grid_images’ and passes the parameters ‘ref_object_type’ and ‘ref_object_id’

2. Create a label field

Create a field of ‘Label’ type within the form / grid and insert it at the place the button will appear.

Our example uses a Label-field named ‘edit_picture’

Then the new field will be filled via PHP-code (i.e. in the event OnLoad):

 

3. Set the Content of the field

Add a usual HTML link (via a href) as contact of the field:

{edit_pictures} = '<a href="' . $string_link . '" class="scButton_small" title="Edit the picture" style="vertical-align: middle; display:inline-block;">' . {lang_contact_edit_pictures} . '</a>';

We’re using the string generated in 1. as link.

‘class’ defines that a small button is to be used. You could also use  class="scButton_default" for a standard button. Hint: Some templates do not support small buttons.

‘title’ defines which text is be shown as popup if the cursor is over the button (PC-browser only).

{lang_contact_edit_pictures} defines which text is shown on the button. (Our sample: Bilder Bearbeiten)
Hint: Use plain text instead of {lang_contact_edit_pictures} of your’re not using the multilingual feature of Scriptcase.

Example:

If the lable field is placed below a picture, ot could be show like:



上面的例子,是連結到外部的Application。

如果是自己FORM/GRID本身的Button呢?

可以先使用SC內的BUTTON功能,建立一個 Button,然後跑跑結果看,用檢視原始碼看該Button的Source Code連結,複製出來。

比照上面的作法,建立一個 Label 欄位,將上段Button複製下來的Source Code貼到該 Label 的內容裡面,

安排該Field顯示在適當的位置。這樣就完成了。

缺點是:原本預設顯示在表頭/表尾的按鈕,必須重複出現。因為如果把該按鈕不顯示,該功能就不行執行了!


如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。