Jump to content

Including modifiers when extending nodes: Difference between revisions

From NusaATK
Juneih (talk | contribs)
No edit summary
Despam
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Howto|easy|[[June Henriksen]] <juneih@linpro.no>}}
{{Howto|advanced|[[June Henriksen]] <juneih@linpro.no>}}


This howto explains how you can include modifiers when you extend a node.
== Intro ==


All modifiers added to a node will be run in the node's init function. Which modifiers that runs however, depends on the m_type of a node, which will be different for any node that extends it. In order to have the modifiers run, some changes has to be made in the extended nodes init node.  
ATK features a concept called '[[modifiers]]' that allows one to change functionality of a node without touching the original code of the node (See the '[[Using modifiers]]' howto).  


<p></p>
The way modifiers work however, prevents modifiers from being applied to classes that extend the node. This may be fixed in a later version of ATK. For now, you can use this howto which presents a workaround to this problem.
An example init_node:
<p></p>
 
<span style="color: #808080; font-style: italic;">/*
  * This file is part of the FSdocu distribution.
  * Detailed copyright and licensing information can be found
  * in the doc/COPYRIGHT and doc/LICENSE files which should be
  * included in the distribution.
  *
  * @package docu
  *
  * @author Fabio Saitta &lt;fabio@saitta.it&gt;
  *
  * @copyright (c)2000-2004 http://www.saitta.it
  * @license http://www.opensource.org/licenses/sleepycat.php
  *
  * @version $Revision: 0.99 $
  * $Id: web.js,v 0.99 2006/11/07 15:48:00 fabio Exp $
  */</span>
 
 
&nbsp;
&nbsp;
fsc=<span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> fs_add<span style="color: #66cc66;">&#40;</span>element<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>fsc==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  Droppables.<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ar_image'</span>, <span style="color: #66cc66;">&#123;</span>onDrop:fs_drop<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
  el1=document.<span style="color: #000000;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"fs_timbro"</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>;
fsc=fsc+<span style="color: #cc66cc;">1</span>;
<span style="color: #000000; font-weight: bold;">var</span> newdiv=document.<span style="color: #000000;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"div"</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> newtext=document.<span style="color: #000000;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Campo"</span>+fsc<span style="color: #66cc66;">&#41;</span>;
newdiv.<span style="color: #000000;">appendChild</span><span style="color: #66cc66;">&#40;</span>newtext<span style="color: #66cc66;">&#41;</span>;
newdiv.<span style="color: #000000;">id</span>=<span style="color: #ff0000;">"fs_div"</span>+fsc;
newdiv.<span style="color: #000000;">alt</span>=<span style="color: #ff0000;">"campo"</span>+fsc;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">textAlign</span>=<span style="color: #ff0000;">"center"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">color</span>=<span style="color: #ff0000;">"#ffffff"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">backgroundColor</span>=<span style="color: #ff0000;">"#7f9f50"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">fontFamily</span>=<span style="color: #ff0000;">"Lucida Grande, Verdana, Arial, Helvetica, sans serif"</span>; 
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">fontSize</span>=<span style="color: #ff0000;">"11px"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">width</span>=<span style="color: #ff0000;">"70px"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">position</span>=<span style="color: #ff0000;">"absolute"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">top</span>=<span style="color: #66cc66;">&#40;</span>el1.<span style="color: #000000;">offsetTop</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">"px"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">left</span>=<span style="color: #66cc66;">&#40;</span>el1.<span style="color: #000000;">offsetLeft</span>+<span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">"px"</span>;
el=document.<span style="color: #000000;">body</span>;
el.<span style="color: #000000;">appendChild</span><span style="color: #66cc66;">&#40;</span>newdiv<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">new</span> Draggable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"fs_div"</span>+fsc<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> fs_pos<span style="color: #66cc66;">&#40;</span><span style="color: #000066;">name</span>,x,y<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>fsc==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  Droppables.<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ar_image'</span>, <span style="color: #66cc66;">&#123;</span>onDrop:fs_drop<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
  el1=document.<span style="color: #000000;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"fs_timbro"</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>;
fsc=fsc+<span style="color: #cc66cc;">1</span>;
<span style="color: #000000; font-weight: bold;">var</span> newdiv=document.<span style="color: #000000;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"div"</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> newtext=document.<span style="color: #000000;">createTextNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">name</span><span style="color: #66cc66;">&#41;</span>;
newdiv.<span style="color: #000000;">appendChild</span><span style="color: #66cc66;">&#40;</span>newtext<span style="color: #66cc66;">&#41;</span>;
newdiv.<span style="color: #000000;">id</span>=<span style="color: #ff0000;">"fs_div"</span>+fsc;
newdiv.<span style="color: #000000;">alt</span>=<span style="color: #000066;">name</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">textAlign</span>=<span style="color: #ff0000;">"center"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">color</span>=<span style="color: #ff0000;">"#ffffff"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">backgroundColor</span>=<span style="color: #ff0000;">"#7f9f50"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">fontFamily</span>=<span style="color: #ff0000;">"Lucida Grande, Verdana, Arial, Helvetica, sans serif"</span>; 
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">fontSize</span>=<span style="color: #ff0000;">"11px"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">width</span>=<span style="color: #ff0000;">"70px"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">position</span>=<span style="color: #ff0000;">"absolute"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">top</span>=<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">"px"</span>;
newdiv.<span style="color: #000000;">style</span>.<span style="color: #000000;">left</span>=<span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">"px"</span>;
el=document.<span style="color: #000000;">body</span>;
el.<span style="color: #000000;">appendChild</span><span style="color: #66cc66;">&#40;</span>newdiv<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">new</span> Draggable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"fs_div"</span>+fsc<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showResponse <span style="color: #66cc66;">&#40;</span>originalRequest<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
$<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'loading'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000000;">style</span>.<span style="color: #000000;">display</span> = <span style="color: #ff0000;">"none"</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> showLoad <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
$<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'loading'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000000;">style</span>.<span style="color: #000000;">display</span> = <span style="color: #ff0000;">"inline"</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> fs_drop<span style="color: #66cc66;">&#40;</span>element,droppableElement<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span>
class.FSfield.inc
 
 
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">/*
  * This file is part of the FSdocu distribution.
  * Detailed copyright and licensing information can be found
  * in the doc/COPYRIGHT and doc/LICENSE files which should be
  * included in the distribution.
  *
  * @package docu
  *
  * @author Fabio Saitta &lt;fabio@saitta.it&gt;
  *
  * @copyright (c)2000-2004 http://www.saitta.it
  * @license http://www.opensource.org/licenses/sleepycat.php
  *
  * @version $Revision: 0.99 $
  * $Id: class.Fsfield.inc,v 0.99 2006/11/07 15:48:00 fabio Exp $
  */</span>
&nbsp;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atknumberattribute"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkcurrencyattribute"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkFileAttribute"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkboolattribute"</span><span style="color: #66cc66;">&#41;</span>;
userelation<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkmanytoonerelation"</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">class</span> FSfield extends atkNode
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> FSfield<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">atkNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'FSfield'</span>,NF_ADD_LINK|NF_ADDAFTERADD<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"id"</span> ,AF_NO_QUOTES |AF_AUTOKEY<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"descri"</span> ,AF_SEARCH<span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkNumberAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"xcord"</span> ,AF_SEARCH<span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkNumberAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"ycord"</span> ,AF_SEARCH<span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkManyToOneRelation<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"image"</span>,<span style="color: #ff0000;">"image.FSimage"</span>,AF_OBLIGATORY|AF_NO_QUOTES|AF_SEARCHABLE<span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">setTable</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'fs_field'</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">setSecurityAlias</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"image.FSimage"</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
   
    <span style="color: #000000; font-weight: bold;">function</span> descriptor_def<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"[descri]"</span>;
    <span style="color: #66cc66;">&#125;</span>   
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
 
<strong>class FSImage</strong> creates a thumbnail of form image (jpeg, gif or png) and shows it in <strong>Recordlist</strong> mode
<p></p>
main class load <strong>prototype.js</strong> and <strong>scriptaculous.js</strong> as well as  <strong>web.js</strong> and <strong>web.css</strong>
 
<p></p>
Function <strong>editPage</strong>:
<p></p>
<ul>
<li>stores <strong>key</strong> value in <strong>reg_id</strong> <em>session variable</em> for insert or update new field value later on.</li>
</ul>
 
<ul>
<li>Creates two new little images (icons) <strong>postit</strong> and <strong>stamp</strong> and attach <em>double click event</em> to them.</li>
</ul>
<ul>
<li>Creates a new little image for <em>ajax</em> activity and hide it.</li>


</ul>
== Adding modifiers to derived nodes ==
<ul>
<li>Calls several time function <strong>fs_pos</strong> to arrange the position of all the field already stored in DB.</li>
</ul>
<ul>
<li>Defines <strong>fs_salva</strong> (field save) to store or update field position (you can move the field dragging them all over the form). <strong>Fs_salva</strong> is dynamic because has to store <em>stackID</em> value used for retrieve <strong>reg_id</strong> <em>session variable</em>. Call Ajax to save fields position</li>


</ul>
All modifiers added to a node run from the node's init function. Which modifiers that runs however, depends on the m_type of a node. When you extend a node, you get a new m_type if you set the atkNode in the constructor.
<p></p>
Action <strong>ajaxupdate</strong>:
<p></p>
<ul>
<li>decodes field name, x position and y position</li>
</ul>
<ul>
<li>retrieves <strong>master-detail</strong> key <strong>id</strong> from <strong>reg_id</strong> <em>session variable</em></li>


</ul>
<span style="color: #000000; font-style: italic;">
<ul>
$this->atkNode("nodename");
<li>verify if detail record exists</li>
</span>
<ul>
<li><em>if yes</em> call <strong>sql update</strong> to modify it</li>
</ul>
<ul>
<li><em>if no</em>  call <strong>sql insert</strong> to create it</li>


</ul>
In order to have the modifiers run, some changes has to be made in the extended node's init node.  
</ul>
<p></p>
<p></p>
<p></p>
class.FSImage.inc
<p></p>
 
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #808080; font-style: italic;">/*
  * This file is part of the FSdocu distribution.
  * Detailed copyright and licensing information can be found
  * in the doc/COPYRIGHT and doc/LICENSE files which should be
  * included in the distribution.
  *
  * @package docu
  *
  * @author Fabio Saitta &lt;fabio@saitta.it&gt;
  *
  * @copyright (c)2000-2004 http://www.saitta.it
  * @license http://www.opensource.org/licenses/sleepycat.php
  *
  * @version $Revision: 0.99 $
  * $Id: class.Fsimage.inc,v 0.99 2006/11/07 15:48:00 fabio Exp $
  */</span>
userelation<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkOneToManyRelation"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atknumberattribute"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkcurrencyattribute"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkFileAttribute"</span><span style="color: #66cc66;">&#41;</span>;
useattrib<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkboolattribute"</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">class</span> sepiaAttribute extends atkFileAttribute
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// By overriding this method, we can do processing on the uploaded image.</span>
    <span style="color: #808080; font-style: italic;">// The path and filename of the image are passed as parameters.</span>
    <span style="color: #000000; font-weight: bold;">function</span> processFile<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$path</span>, <span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #808080; font-style: italic;">// Include the image class we downloaded. By using the 'moduleDir' method, we</span>
      <span style="color: #808080; font-style: italic;">// ensure that our module works regardless of where it is installed.</span>
   
    <span style="color: #0000ff;">$dest_width</span>=<span style="color: #cc66cc;">100</span>;
    <span style="color: #0000ff;">$dest_height</span>=<span style="color: #cc66cc;">100</span>;
    <span style="color: #0000ff;">$ext</span> = <span style="color: #000066;">substr</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$filename</span>, <span style="color: #000066;">strrpos</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$filename</span>, <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$ext</span> == <span style="color: #ff0000;">'jpg'</span> || <span style="color: #0000ff;">$ext</span> == <span style="color: #ff0000;">'jpeg'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$src</span> = imagecreatefromjpeg<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$filename</span> <span style="color: #66cc66;">&#41;</span> or <span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Cannot load input JPEG image'</span> <span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$ext</span> == <span style="color: #ff0000;">'gif'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$src</span> = imagecreatefromgif<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$filename</span> <span style="color: #66cc66;">&#41;</span> or <span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Cannot load input GIF image'</span> <span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$ext</span> == <span style="color: #ff0000;">'png'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$src</span> = imagecreatefrompng<span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$filename</span> <span style="color: #66cc66;">&#41;</span> or <span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Cannot load input PNG image'</span> <span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">else</span> <span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Unsupported source file format'</span> <span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000066;">list</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #000066;">getimagesize</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$dst</span> = imagecreatetruecolor<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dest_width</span>, <span style="color: #0000ff;">$dest_height</span><span style="color: #66cc66;">&#41;</span>;
    imagecopyresampled<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dst</span>, <span style="color: #0000ff;">$src</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0000ff;">$dest_width</span>, <span style="color: #0000ff;">$dest_height</span>, <span style="color: #0000ff;">$width</span>, <span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$thumb</span> = <span style="color: #ff0000;">"thumb_"</span>.<span style="color: #0000ff;">$filename</span>;
    imagepng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dst</span>, <span style="color: #0000ff;">$path</span>.<span style="color: #0000ff;">$thumb</span><span style="color: #66cc66;">&#41;</span>;
    imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> display<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$record</span>, <span style="color: #0000ff;">$mode</span>=<span style="color: #ff0000;">""</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #808080; font-style: italic;">// In recodlists, show the thumbnail instead of the larger image.</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$mode</span>==<span style="color: #ff0000;">"list"</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// use the thumb_... version of the image</span>
        <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">'&lt;img src=&quot;'</span>.<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">m_url</span>.<span style="color: #ff0000;">"thumb_"</span>.<span style="color: #0000ff;">$record</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">fieldName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"orgfilename"</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">'&quot;&gt;'</span>;
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #b1b100;">return</span> parent::<span class="me2">display</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$record</span>, <span style="color: #0000ff;">$mode</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #000000; font-weight: bold;">class</span> FSimage extends atkNode
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> FSimage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">atkNode</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'FSimage'</span>,NF_ADD_LINK|NF_ADDAFTERADD<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$page</span> = &amp;<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">getPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$page</span>-&gt;<span style="color: #000000;">register_script</span><span style="color: #66cc66;">&#40;</span>atkconfig<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkroot"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">"atk/javascript/prototype/prototype.js"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$page</span>-&gt;<span style="color: #000000;">register_script</span><span style="color: #66cc66;">&#40;</span>atkconfig<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"atkroot"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">"atk/javascript/scriptaculous/scriptaculous.js"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$page</span>-&gt;<span style="color: #000000;">register_script</span><span style="color: #66cc66;">&#40;</span>moduleDir<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"image"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">"web.js"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$page</span>-&gt;<span style="color: #000000;">register_style</span><span style="color: #66cc66;">&#40;</span>moduleDir<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"image"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">"web.css"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"id"</span> ,AF_NO_QUOTES |AF_AUTOKEY<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sepiaAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"image"</span>, <span style="color: #ff0000;">"../docu/"</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkOneToManyRelation<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"dettagli"</span>, <span style="color: #ff0000;">"image.FSfield"</span>, <span style="color: #ff0000;">"image"</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> atkAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"descri"</span>, AF_OBLIGATORY<span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">"Registro"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">setTable</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'fs_image'</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
   
    <span style="color: #000000; font-weight: bold;">function</span> editPage<span style="color: #66cc66;">&#40;</span>&amp;<span style="color: #0000ff;">$handler</span>, <span style="color: #0000ff;">$record</span>, <span style="color: #0000ff;">$locked</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000066;">global</span> <span style="color: #0000ff;">$g_sessionManager</span>;
      <span style="color: #0000ff;">$g_sessionManager</span>-&gt;<span style="color: #000000;">stackVar</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"reg_id"</span>,<span style="color: #0000ff;">$record</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'id'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$content</span>= <span style="color: #ff0000;">'&lt;img src=&quot;/docu/postit.jpg&quot; id=&quot;fs_postit&quot; ondblclick=&quot;fs_add(this)&quot; alt=&quot;Crea Campo&quot;&gt;'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #ff0000;">'&lt;img src=&quot;/docu/timbro.jpg&quot; id=&quot;fs_timbro&quot; ondblclick=&quot;fs_salva(this)&quot; alt=&quot;Salva Campi&quot;&gt;'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #ff0000;">'&lt;img id=&quot;loading&quot; src=&quot;/docu/Loading.gif&quot; alt&quot;Loading...&quot;&gt;'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #ff0000;">'&lt;div id=&quot;zipResult&quot;&gt;&lt;/div&gt;'</span>;
      <span style="color: #0000ff;">$content</span>.=<span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'&lt;script type=&quot;text/javascript&quot;&gt;'</span>.<span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #808080; font-style: italic;">// ora mi prendo tutti i campi del file</span>
      <span style="color: #0000ff;">$g_db</span> = &amp;<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">getDb</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">"SELECT descri,xcord,ycord FROM fs_field where image="</span>.<span style="color: #0000ff;">$record</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"id"</span><span style="color: #66cc66;">&#93;</span>;
      <span style="color: #0000ff;">$g_db</span>-&gt;<span style="color: #000000;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span>, <span style="color: #0000ff;">$offset</span>, <span style="color: #0000ff;">$limit</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$g_db</span>-&gt;<span style="color: #000000;">next_record</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$result</span> = <span style="color: #0000ff;">$g_db</span>-&gt;<span style="color: #000000;">m_record</span>;
        <span style="color: #0000ff;">$content</span>.=<span style="color: #ff0000;">'fs_pos(&quot;'</span>.<span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"descri"</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">'&quot;,'</span>.<span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"xcord"</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">','</span>.<span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">"ycord"</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #ff0000;">");"</span>.<span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>;
  <span style="color: #808080; font-style: italic;">// creo la parte di update ajax</span>
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'function fs_salva(element)'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'{'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'var url=&quot;dispatch.php&quot;;'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'for (i = 1; i &lt;= fsc; i++)'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'{'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'el=document.getElementById(&quot;fs_div&quot;+i);'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'if (el != undefined)'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'{'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'var pars  = &quot;atknodetype=image.FSimage&amp;atkaction=ajaxupdate&amp;atklevel=2&amp;atkprevlevel=1&amp;atkstackid='</span>.atkStackID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'&amp;field=&quot; + el.alt + &quot;&amp;x=&quot; + el.style.top+ &quot;&amp;y=&quot; + el.style.left;'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'var myAjax = new Ajax.Updater({success: &quot;zipResult&quot;}, url, {method: &quot;get&quot;, parameters: pars, onLoading: showLoad, onComplete: showResponse} );'</span>;
      <span style="color: #0000ff;">$content</span>.= <span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">'}}}'</span>;
      <span style="color: #0000ff;">$content</span>.=<span style="color: #ff0000;">'&lt;/script&gt;'</span>.<span style="color: #000066;">chr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$page</span> = <span style="color: #0000ff;">$handler</span>-&gt;<span style="color: #000000;">editPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$record</span>, <span style="color: #0000ff;">$locked</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0000ff;">$content</span>;
      <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> descriptor_def<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"[descri]"</span>;
      <span style="color: #66cc66;">&#125;</span>   
   
    <span style="color: #000000; font-weight: bold;">function</span> action_ajaxupdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">//  function action_ajaxupdate($field=&quot;&quot;,$x=0,$y=0)</span>
      <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000066;">global</span> <span style="color: #0000ff;">$g_sessionManager</span>,<span style="color: #0000ff;">$_GET</span>;
      <span style="color: #0000ff;">$field</span> = <span style="color: #000066;">htmlspecialchars</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'field'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #808080; font-style: italic;">// attenzione px</span>
      <span style="color: #0000ff;">$x</span> = <span style="color: #000066;">htmlspecialchars</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'x'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$y</span> = <span style="color: #000066;">htmlspecialchars</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'y'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$x</span> = <span style="color: #000066;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000066;">strpos</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$x</span>, <span style="color: #ff0000;">'px'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$y</span> = <span style="color: #000066;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$y</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000066;">strpos</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$y</span>, <span style="color: #ff0000;">'px'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$reg_id</span>=<span style="color: #0000ff;">$g_sessionManager</span>-&gt;<span style="color: #000000;">stackVar</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"reg_id"</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #808080; font-style: italic;">// id,field,x,y creare un sql</span>
      <span style="color: #808080; font-style: italic;">// verifico se esiste faccio un update</span>
      <span style="color: #808080; font-style: italic;">// se non esiste faccio un insert</span>
      <span style="color: #0000ff;">$g_db</span> = &amp;<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #000000;">getDb</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">'SELECT * FROM fs_field WHERE descri=&quot;'</span>.<span style="color: #0000ff;">$field</span>.<span style="color: #ff0000;">'&quot; and image = '</span>.<span style="color: #0000ff;">$reg_id</span>;
      <span style="color: #0000ff;">$g_db</span>-&gt;<span style="color: #000000;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span>, <span style="color: #0000ff;">$offset</span>, <span style="color: #0000ff;">$limit</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #808080; font-style: italic;">// attenzione al primo record ???</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$g_db</span>-&gt;<span style="color: #000000;">next_record</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #808080; font-style: italic;">// faccio update </span>
        <span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">'update fs_field set xcord='</span>.<span style="color: #0000ff;">$x</span>.<span style="color: #ff0000;">',ycord='</span>.<span style="color: #0000ff;">$y</span>.<span style="color: #ff0000;">' WHERE descri=&quot;'</span>.<span style="color: #0000ff;">$field</span>.<span style="color: #ff0000;">'&quot; and image = '</span>.<span style="color: #0000ff;">$reg_id</span>;
      <span style="color: #b1b100;">else</span>
      <span style="color: #808080; font-style: italic;">// faccio insert</span>
        <span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">'insert into fs_field (image,descri,xcord,ycord) values ('</span>.<span style="color: #0000ff;">$reg_id</span>.<span style="color: #ff0000;">',&quot;'</span>.<span style="color: #0000ff;">$field</span>.<span style="color: #ff0000;">'&quot;,'</span>.<span style="color: #0000ff;">$x</span>.<span style="color: #ff0000;">','</span>.<span style="color: #0000ff;">$y</span>.<span style="color: #ff0000;">')'</span>;
      <span style="color: #0000ff;">$g_db</span>-&gt;<span style="color: #000000;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span>, <span style="color: #0000ff;">$offset</span>, <span style="color: #0000ff;">$limit</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>


<p></p>
<p></p>
So when you display the full image:
The following is an example init_node for a node that extends the timereg.hours node:
<ul>
<li>All the fields (master-detail) are retrieved from DB</li>
</ul>
<ul>
<li>Master key is stored in a session variable</li>
</ul>
<ul>
<li>A dynamic javascript function is created and:</li>
<ul>
<li>Create a position <em>draggable</em> <strong>DIV</strong> for any of the fields over the image</li>
 
</ul>
<ul>
<li>Attach a function to <em>double-click</em> event of <strong>Stampa</strong> image</li>
</ul>
</ul>
<p></p>
When you <em>double-click</em> on <strong>post-it</strong> image :
 
<ul>
<li>A new field is created</li>
</ul>
<ul>
<li>You can drag it all over the image</li>
</ul>
<ul>
<li>The new field is not stored on DB</li>
</ul>
<p></p>
<p></p>
When you <em>double-click</em> on <strong>stamp</strong> image:


<ul>
<syntaxhighlight lang="php">
<li>You loop on all the field (<em>attention you loop on javascript DIV not on DB</em>)</li>
  function init()
</ul>
  {
<ul>
    $ret = parent::init();
<li>For any of fields you call a <em>Ajax</em> updater function that fires Action <strong>ajaxupdate</strong> with proper parameters</li>
    $oldtype = $this->m_type;
</ul>
    $oldmodule= $this->m_module;
<ul>
    $this->m_type='hours';
    $this->m_module='timereg';
 
    global $g_modifiers;
 
    if (isset($g_modifiers[$this->atknodetype()]))
    {
      foreach ($g_modifiers[$this->atknodetype()] as $modulename)
      {
        $module = &getModule($modulename);
        $module->modifier($this);
      }
    }
    $this->m_module=$oldmodule;
    $this->m_type = $oldtype;
 
    return $ret;
  }
</syntaxhighlight>


<li>ATK information like ATKstack, ATKLevel, ATKPreviouslevel are passed to <strong>Dispatch.php</strong> <em>ATK PHP file</em></li>
As mentioned, this example is for running the modifiers added to the hours node, but this can of course be exchanged for any other node. In fact, the only thing that needs to be changed in this code is the nodename ('hours') and modulename ('timereg')! Remember, the function itself is put in the extending node.
</ul>
<ul>
<li><em>Ajax</em> <em>work-in-progress</em> image is displayed</li>
</ul>
<ul>
<li>When <em>Ajax</em> function called is completed <em>work-in-progress</em> image is hided</li>


</ul>
The result of including this is that you now will have access to all the attributes added by modifiers to the node that is extended.
<p></p>
Action <strong>ajaxupdate</strong> is called from <em>Ajax</em> and:
<ul>
<li>decodes field name, x position and y position (passed by GET parameters)</li>
</ul>
<ul>
<li>retrieves <strong>master-detail</strong> key <strong>id</strong> from <strong>reg_id</strong> <em>session variable</em></li>


</ul>
<ul>
<li>verify if detail record exists</li>
<ul>
<li>if yes call sql update to modify it</li>
</ul>
<ul>
<li>if no  call sql insert to create it</li>
</ul>
</ul>
<p></p>
<p></p>


--[[User:Saitta|Saitta]] 13:07, 10 November 2006 (CEST)
--[[User:juneih|juneih]] 16:29, 23 November 2006 (CEST)

Latest revision as of 06:57, 16 July 2007

ATK Howto: Including modifiers when extending nodes

Complexity: advanced
Author: June Henriksen <juneih@linpro.no>

List of other Howto's

Intro

ATK features a concept called 'modifiers' that allows one to change functionality of a node without touching the original code of the node (See the 'Using modifiers' howto).

The way modifiers work however, prevents modifiers from being applied to classes that extend the node. This may be fixed in a later version of ATK. For now, you can use this howto which presents a workaround to this problem.

Adding modifiers to derived nodes

All modifiers added to a node run from the node's init function. Which modifiers that runs however, depends on the m_type of a node. When you extend a node, you get a new m_type if you set the atkNode in the constructor.

$this->atkNode("nodename");

In order to have the modifiers run, some changes has to be made in the extended node's init node.

The following is an example init_node for a node that extends the timereg.hours node:

  function init()
  {
    $ret = parent::init();
    $oldtype = $this->m_type;
    $oldmodule= $this->m_module;
    $this->m_type='hours';
    $this->m_module='timereg';
  
    global $g_modifiers;
  
    if (isset($g_modifiers[$this->atknodetype()]))
    {
      foreach ($g_modifiers[$this->atknodetype()] as $modulename)
      {
        $module = &getModule($modulename);
        $module->modifier($this);
      }
    }
    $this->m_module=$oldmodule;
    $this->m_type = $oldtype;
  
    return $ret;
  }

As mentioned, this example is for running the modifiers added to the hours node, but this can of course be exchanged for any other node. In fact, the only thing that needs to be changed in this code is the nodename ('hours') and modulename ('timereg')! Remember, the function itself is put in the extending node.

The result of including this is that you now will have access to all the attributes added by modifiers to the node that is extended.


--juneih 16:29, 23 November 2006 (CEST)