Extra button in details view

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Extra button in details view

Post by SSchimkat » 2018-07-12 07:13

Hi everyone

New to AppGini .. and what a thrill. So easy to make great db apps. :-)

One question: How would I go about adding an extra button to the details view? I would like to have a button that updated a few fields in the current record with some predefined values. A hint on that one please. :-)

SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Re: Extra button in details view

Post by SSchimkat » 2018-07-13 21:20

Getting on with it .. but now I'm stuck. I've added the buttons, but I'm having a hard time locating the actual code executed by the button. Where is the code for ie. the update button?

$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return Packages_validateData();" ....

My new button's .. looking great. Now they just need to actually do something. :-)

Image

SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Re: Extra button in details view

Post by SSchimkat » 2018-07-13 21:51

ok .. it's getting funny .. or strange. Not sure which. :-D

I've found the code being executed for updating a record: [root]/[tablename]_dml.php .. and the function containing the code for updating is [tablename]_update($selected_id).

Now I just need to figure out how this function is called from the update button, and then I can copy the code for my new buttons .. but now the fun starts: The function [tablename]_update isn't used at all - I cannot find any calls for this function. That doesn't make sense at all - I know .. but it does mean the I could use a hint on how the function is called from the button - where is the route from the button to the function? :-)

Best regards, Søren

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Extra button in details view

Post by grimblefritz » 2018-07-13 22:59

I'd recommend investing in the Udemy course. It will have you teaching AppGini to sing and dance in no time.

SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Re: Extra button in details view

Post by SSchimkat » 2018-07-16 11:10

Anyone with a hint on how the functions in [tablename]_dml.php is called from buttons in the detail view? :-)

SSchimkat
Veteran Member
Posts: 31
Joined: 2018-01-04 18:49

Re: Extra button in details view

Post by SSchimkat » 2018-07-16 21:33

Got it working. Here is what i did (quite specific for my project .. I know .. but here goes):

Code: Select all

diff -Naur PackMan.ORG/datalist.php PackMan/datalist.php
--- PackMan.ORG/datalist.php	2018-07-16 23:21:21.672528134 +0200
+++ PackMan/datalist.php	2018-07-16 23:21:15.912578690 +0200
@@ -148,6 +148,11 @@
 		$SelectedID = (get_magic_quotes_gpc() ? stripslashes($_REQUEST['SelectedID']) : $_REQUEST['SelectedID']);
 		$insert_x = $_REQUEST['insert_x'];
 		$update_x = $_REQUEST['update_x'];
+		$packstart_x = $_REQUEST['packstart_x'];
+		$packcomplete_x = $_REQUEST['packcomplete_x'];
+		$teststart_x = $_REQUEST['teststart_x'];
+		$testcomplete_x = $_REQUEST['testcomplete_x'];
+		$invoiced_x = $_REQUEST['invoiced_x'];
 		$delete_x = $_REQUEST['delete_x'];
 		$SkipChecks = $_REQUEST['confirmed'];
 		$deselect_x = $_REQUEST['deselect_x'];
@@ -182,6 +187,12 @@
 		}
 		if(!$this->AllowUpdate){
 			$update_x = '';
+			$packstart_x = '';
+			$packcomplete_x = '';
+			$teststart_x = '';
+			$testcomplete_x = '';
+			$invoiced_x = '';
+
 		}
 		if(!$this->AllowFilters){
 			$Filter_x = '';
@@ -319,8 +330,14 @@
 			}
 		}
 
-		elseif($update_x != ''){
-			$updated = call_user_func($this->TableName.'_update', $SelectedID);
+		elseif(($update_x != '') OR ($packstart_x != '') OR ($packcomplete_x != '') OR ($teststart_x != '') OR ($testcomplete_x != '') OR ($invoiced_x != '')){
+
+			if ($update_x != '') {$updated = call_user_func($this->TableName.'_update', $SelectedID);}
+			if ($packstart_x != '') {$updated = call_user_func('Packages_packstart', $SelectedID);}
+			if ($packcomplete_x != '') {$updated = call_user_func('Packages_packcomplete', $SelectedID);}
+			if ($teststart_x != '') {$updated = call_user_func('Packages_teststart', $SelectedID);}
+			if ($testcomplete_x != '') {$updated = call_user_func('Packages_testcomplete', $SelectedID);}
+			if ($invoiced_x != '') {$updated = call_user_func('Packages_invoiced', $SelectedID);}
 
 			$update_status = 'record-updated-ok=' . rand();
 			if($updated === false) $update_status = 'record-updated-error=' . rand();
diff -Naur PackMan.ORG/Packages_dml.php PackMan/Packages_dml.php
--- PackMan.ORG/Packages_dml.php	2018-07-16 23:21:24.476503522 +0200
+++ PackMan/Packages_dml.php	2018-07-16 23:21:18.628554856 +0200
@@ -5,6 +5,126 @@
 // This script and data application were generated by AppGini 5.72
 // Download AppGini for free from https://bigprof.com/appgini/download/
 
+function Packages_packstart($selected_id) {
+
+        global $Translation;
+
+        // mm: can member edit record?
+        $arrPerm=getTablePermissions('Packages');
+        $ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        $ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
+                // update allowed, so continue ...
+        }else{
+                return false;
+        }
+
+       $o=array('silentErrors' => true);
+       sql('update `Packages` set `AssignedTo`="' . getMemberInfo()['username'] . "\", `State`= 2 where `ID`='".makeSafe($selected_id)."'", $o);
+       if($o['error']!=''){
+               echo $o['error'];
+               echo '<a href="Packages_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
+               exit;
+       }
+
+}
+
+function Packages_packcomplete($selected_id) {
+
+        global $Translation;
+
+        // mm: can member edit record?
+        $arrPerm=getTablePermissions('Packages');
+        $ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        $ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
+                // update allowed, so continue ...
+        }else{
+                return false;
+        }
+
+        $o=array('silentErrors' => true);
+        sql('update `Packages` set `AssignedTo`="Nobody", `State`= 3 where `ID`="' . makeSafe($selected_id) . '"', $o);
+        if($o['error']!=''){
+                echo $o['error'];
+                echo '<a href="Packages_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
+                exit;
+        }
+
+}
+
+function Packages_teststart($selected_id) {
+
+        global $Translation;
+
+        // mm: can member edit record?
+        $arrPerm=getTablePermissions('Packages');
+        $ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        $ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
+                // update allowed, so continue ...
+        }else{
+                return false;
+        }
+
+        $o=array('silentErrors' => true);
+        sql('update `Packages` set `AssignedTo`="' . getMemberInfo()['username'] . "\", `State`= 3 where `ID`='".makeSafe($selected_id)."'", $o);
+        if($o['error']!=''){
+                echo $o['error'];
+                echo '<a href="Packages_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
+                exit;
+        }
+
+}
+
+function Packages_testcomplete($selected_id) {
+
+        global $Translation;
+
+        // mm: can member edit record?
+        $arrPerm=getTablePermissions('Packages');
+        $ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        $ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
+                // update allowed, so continue ...
+        }else{
+                return false;
+        }
+
+        $o=array('silentErrors' => true);
+        sql('update `Packages` set `AssignedTo`="Nobody", `DateCompleted`="' . date("Y/m/d") . '", `State`= 4 where `ID`="' . makeSafe($selected_id) . '"', $o);
+        if($o['error']!=''){
+                echo $o['error'];
+                echo '<a href="Packages_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
+                exit;
+        }
+
+}
+
+function Packages_invoiced($selected_id) {
+
+        global $Translation;
+
+        // mm: can member edit record?
+        $arrPerm=getTablePermissions('Packages');
+        $ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        $ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='Packages' and pkValue='".makeSafe($selected_id)."'");
+        if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
+                // update allowed, so continue ...
+        }else{
+                return false;
+        }
+
+        $o=array('silentErrors' => true);
+        sql('update `Packages` set `AssignedTo`="Regnskab", `Invoiced`="Yes" where `ID`="' . makeSafe($selected_id) . '"', $o);
+        if($o['error']!=''){
+                echo $o['error'];
+                echo '<a href="Packages_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
+                exit;
+        }
+
+}
+
 function Packages_insert(){
 	global $Translation;
 
@@ -749,8 +869,19 @@
 		if(!$_REQUEST['Embedded']) $templateCode = str_replace('<%%DVPRINT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="dvprint" name="dvprint_x" value="1" onclick="$$(\'form\')[0].writeAttribute(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;" title="' . html_attr($Translation['Print Preview']) . '"><i class="glyphicon glyphicon-print"></i> ' . $Translation['Print Preview'] . '</button>', $templateCode);
 		if($AllowUpdate){
 			$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return Packages_validateData();" title="' . html_attr($Translation['Save Changes']) . '"><i class="glyphicon glyphicon-ok"></i> ' . $Translation['Save Changes'] . '</button>', $templateCode);
+			$templateCode = str_replace('<%%START_PACKAGING_BUTTON%%>', '<button type="submit" class="btn btn-default btn-lg" id="packstart" name="packstart_x" value="1" onclick="return Packages_validateData();" title="Packagaging Started"><i class="glyphicon glyphicon-exclamation-sign"></i> Packaging Started</button>', $templateCode);
+			$templateCode = str_replace('<%%COMPLETE_PACKAGING_BUTTON%%>', '<button type="submit" class="btn btn-default btn-lg" id="packcomplete" name="packcomplete_x" value="1" onclick="return Packages_validateData();" title="Packaging Completed"><i class="glyphicon glyphicon-ok"></i> Packaging Completed</button>', $templateCode);
+			$templateCode = str_replace('<%%START_TESTING_BUTTON%%>', '<button type="submit" class="btn btn-default btn-lg" id="teststart" name="teststart_x" value="1" onclick="return Packages_validateData();" title="Testing Started"><i class="glyphicon glyphicon-exclamation-sign"></i> Testing Started</button>', $templateCode);
+			$templateCode = str_replace('<%%COMPLETE_TESTING_BUTTON%%>', '<button type="submit" class="btn btn-default btn-lg" id="testcomplete" name="testcomplete_x" value="1" onclick="return Packages_validateData();" title="Testing Completed"><i class="glyphicon glyphicon-ok"></i> Testing Completed</button>', $templateCode);
+			$templateCode = str_replace('<%%INVOICED_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="invoiced" name="invoiced_x" value="1" onclick="return Packages_validateData();" title="Package Invoiced"><i class="glyphicon glyphicon-ok"></i> Package Invoiced</button>', $templateCode);
 		}else{
 			$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);
+			$templateCode = str_replace('<%%START_PACKAGING_BUTTON%%%>', '', $templateCode);
+			$templateCode = str_replace('<%%COMPLETE_PACKAGING_BUTTON%%>', '', $templateCode);
+			$templateCode = str_replace('<%%START_TESTING_BUTTON%%>', '', $templateCode);
+			$templateCode = str_replace('<%%COMPLETE_TESTING_BUTTON%%>', '', $templateCode);
+			$templateCode = str_replace('<%%INVOICED_BUTTON%%>', '', $templateCode);
+
 		}
 		if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
 			$templateCode = str_replace('<%%DELETE_BUTTON%%>', '<button type="submit" class="btn btn-danger" id="delete" name="delete_x" value="1" onclick="return confirm(\'' . $Translation['are you sure?'] . '\');" title="' . html_attr($Translation['Delete']) . '"><i class="glyphicon glyphicon-trash"></i> ' . $Translation['Delete'] . '</button>', $templateCode);
diff -Naur PackMan.ORG/templates/Packages_templateDV.html PackMan/templates/Packages_templateDV.html
--- PackMan.ORG/templates/Packages_templateDV.html	2018-07-16 23:21:42.834342385 +0200
+++ PackMan/templates/Packages_templateDV.html	2018-07-16 23:21:33.279426193 +0200
@@ -138,6 +138,13 @@
 				</div><p></p>
 				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
 					<%%INSERT_BUTTON%%>
+				</div><p></p>
+				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
+                   <%%START_PACKAGING_BUTTON%%>
+                   <%%COMPLETE_PACKAGING_BUTTON%%>
+                   <%%START_TESTING_BUTTON%%>
+                   <%%COMPLETE_TESTING_BUTTON%%>
+                   <%%INVOICED_BUTTON%%>
 				</div>
 			</div>
 		</div>

Post Reply