{"id":319,"date":"2014-12-09T21:45:59","date_gmt":"2014-12-09T20:45:59","guid":{"rendered":"http:\/\/ipsview.brownson.at\/?p=319"},"modified":"2014-12-10T21:41:30","modified_gmt":"2014-12-10T20:41:30","slug":"view-bereich-mit-codeeingabe-schuetzen","status":"publish","type":"post","link":"https:\/\/ipsview.brownson.at\/?p=319","title":{"rendered":"View Bereich mit Codeeingabe sch\u00fctzen"},"content":{"rendered":"<p>\u00c4hnlich dem Vorgehen zum Code gesch\u00fctzten Ein- und Ausschalten einer Alarmanlage, kann man auch den Schutz eines View Bereiches realisieren.<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_Console1.png\"><img decoding=\"async\" class=\"alignnone wp-image-322 size-full\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_Console1.png\" alt=\"IPSView_ViewProtection_Console1\" width=\"799\" height=\"108\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_Console1-200x27.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_Console1-300x40.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_Console1.png 799w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><\/a><\/p>\n<p>Folgendes Skript beinhaltet die komplette Programmlogik und erzeugt nach dem erstmaligen Ausf\u00fchren auch alle ben\u00f6tigten Variablen:<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"View Protection Script\">&lt;?\r\n\r\n\t\/**\r\n\t * @file          IPSView_ViewProtection.ips.php\r\n\t * @author        brownson\r\n\t * @version\r\n\t *   Version 1.0, 2014-11-20 brownson: Initiale Version&lt;br\/&gt;\r\n\t *\r\n\t * Skript um einen Schutz eines View Bereiches mittles Codeeingabe zu\r\n\t * realisieren.\r\n\t *\r\n\t * Konfiguration Einstellungen:\r\n\t *   PROTECTION_CODE         ... Code der eingegeben werden muss um die\r\n\t *                               Sperre auszuschalten.\r\n\t *   PROTECTION_SHOWLASTCHAR ... Spezifiziert ob das letzt eingegebene Zeichen\r\n\t *                               im Klartext angezeigt werden soll.\r\n\t *   PROTECTION_MESSAGEERROR ... Spezifiziert die Fehlermeldung die im Falle\r\n\t *                               einer ung\u00fcltigen Eingabe angezeigt werden soll.\r\n\t *   PROTECTION_MESSAGEOFF   ... Spezifiziert die Anzeige im Status Off.\r\n\t *   PROTECTION_MESSAGEON    ... Spezifiziert die Anzeige im Status ON.\r\n\t *\r\n\t *   Protection_SetOn        ... Hier k\u00f6nnen Befehle platziert werden, die beim\r\n\t *                               Einschalten der Sperre ausgef\u00fchrt werden\r\n\t *                               sollen.\r\n\t *   Protection_SetOff       ... Hier k\u00f6nnen Befehle platziert werden, die beim\r\n\t *                               Ausschalten der Sperre ausgef\u00fchrt werden\r\n\t *                               sollen.\r\n\t *\r\n\t *\/\r\n\r\n\t\/*\r\n\t * Konfiguration:\r\n\t * -------------------------------------------------------------------------\r\n\t *\/\r\n\r\n\tdefine (&#039;PROTECTION_CODE&#039;,\t\t\t\t\t&#039;1234&#039;);\r\n\tdefine (&#039;PROTECTION_SHOWLASTCHAR&#039;,\t\ttrue);\r\n\tdefine (&#039;PROTECTION_MESSAGEERROR&#039;,\t\t&#039;Code Eingabe ist NICHT korrekt!&#039;);\r\n\tdefine (&#039;PROTECTION_MESSAGEOFF&#039;,      \t&#039;Entsperrt&#039;);\r\n\tdefine (&#039;PROTECTION_MESSAGEON&#039;,       \t&#039;Codeeingabe erforderlich&#039;);\r\n\r\n\tfunction Protection_SetOn() {\r\n\t}\r\n\r\n\tfunction Protection_SetOff() {\r\n\t}\r\n\r\n\t\/*\r\n\t * Programmlogik:\r\n\t * -------------------------------------------------------------------------\r\n\t *\/\r\n\t$scriptID     = $_IPS[&#039;SELF&#039;];\r\n\t$sender       = $_IPS[&#039;SENDER&#039;];\r\n\t$parentID     = IPS_GetParent($scriptID);\r\n\r\n\t$variableIDStatus  = CreateVariable(&#039;Status&#039;,  0, $parentID, 10, &#039;~Switch&#039;, $scriptID);\r\n\t$variableIDHidden  = CreateVariable(&#039;Hidden&#039;,  0, $parentID, 15, &#039;~Switch&#039;, null);\r\n\t$variableIDDisplay = CreateVariable(&#039;Display&#039;, 3, $parentID, 20, &#039;~String&#039;, null);\r\n\t$variableIDCode    = CreateVariable(&#039;Code&#039;,    3, $parentID, 30, &#039;~String&#039;, null);\r\n\r\n\tif ($sender==&#039;Execute&#039;) {\r\n\t   \/\/ Only create Variables in manuell Mode\r\n\t} else {\r\n\t\t$variableId   = array_key_exists(&#039;VARIABLE&#039;, $_IPS) ? $_IPS[&#039;VARIABLE&#039;] : 0;\r\n\t\t$value        = $_IPS[&#039;VALUE&#039;];\r\n\t\tif ($variableId == $variableIDStatus) {\r\n\t\t   if ($value==true and !GetValue($variableIDStatus)) {\r\n\t\t      Protection_SetOn();\r\n\t\t      SetValue($variableIDStatus, true);\r\n\t\t      SetValue($variableIDHidden, false);\r\n\t\t\t\tSetValue($variableIDDisplay, PROTECTION_MESSAGEON);\r\n\t\t\t} else if ($value==false and GetValue($variableIDStatus) and Protection_CodeMatches($variableIDCode)) {\r\n\t\t      Protection_SetOff();\r\n\t\t      Protection_ClearCode($variableIDCode, $variableIDDisplay);\r\n\t\t      SetValue($variableIDStatus, false);\r\n\t\t      SetValue($variableIDHidden, true);\r\n\t\t\t\tSetValue($variableIDDisplay, PROTECTION_MESSAGEOFF);\r\n\t\t\t} else if ($value==false and GetValue($variableIDStatus) and !Protection_CodeMatches($variableIDCode)) {\r\n\t\t\t\tSetValue($variableIDDisplay, PROTECTION_MESSAGEERROR);\r\n\t\t\t} else {\r\n\t\t\t\t\/\/ Nothing to do\r\n\t\t\t}\r\n\t\t} else if ($variableId == $variableIDHidden) {\r\n\t\t   \/\/ no Update allowed\r\n\t\t} else if ($variableId == $variableIDDisplay) {\r\n\t\t   \/\/ no Update allowed\r\n\t\t} else if ($variableId == $variableIDCode) {\r\n\t\t   \/\/ no Update allowed\r\n\t\t} else {\r\n\t\t\tswitch ($value) {\r\n\t\t\t\tcase &#039;0&#039;:\r\n\t\t\t\tcase &#039;1&#039;:\r\n\t\t\t\tcase &#039;2&#039;:\r\n\t\t\t\tcase &#039;3&#039;:\r\n\t\t\t\tcase &#039;4&#039;:\r\n\t\t\t\tcase &#039;5&#039;:\r\n\t\t\t\tcase &#039;6&#039;:\r\n\t\t\t\tcase &#039;7&#039;:\r\n\t\t\t\tcase &#039;8&#039;:\r\n\t\t\t\tcase &#039;9&#039;:\r\n\t\t\t\t\tProtection_AddDigitToCode($variableIDCode, $variableIDDisplay, $value);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase &#039;B&#039;:\r\n\t\t\t\t\tProtection_ClearDigitFromCode($variableIDCode, $variableIDDisplay);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase &#039;C&#039;:\r\n\t\t\t\t\tProtection_ClearCode($variableIDCode, $variableIDDisplay);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t   \/\/ do nothing\r\n\t\t\t\t   break;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\/*\r\n\t * Funktionen:\r\n\t * -------------------------------------------------------------------------\r\n\t *\/\r\n\tfunction Protection_CodeMatches($variableIDCode) {\r\n\t   return GetValue($variableIDCode)==PROTECTION_CODE;\r\n\t}\r\n\r\n\tfunction Protection_ClearCode($variableIDCode, $variableIDDisplay) {\r\n\t   SetValue($variableIDCode, &#039;&#039;);\r\n\t   SetValue($variableIDDisplay, &#039;&#039;);\r\n\t}\r\n\r\n\tfunction Protection_BuildDisplayString($variableIDCode, $variableIDDisplay) {\r\n\t   $display = &#039;&#039;;\r\n\t   $code    = GetValue($variableIDCode);\r\n\t   $len     = strlen($code);\r\n\t   for ($pos=0; $pos&lt;$len ; $pos++) {\r\n\t      if ($pos+1==$len and PROTECTION_SHOWLASTCHAR) {\r\n\t\t      $display = $display.substr($code, -1);\r\n\t      } else {\r\n\t\t      $display = $display.&#039;*&#039;;\r\n\t      }\r\n\t   }\r\n\t   SetValue($variableIDDisplay, $display);\r\n\t}\r\n\r\n\tfunction Protection_AddDigitToCode($variableIDCode, $variableIDDisplay, $value) {\r\n\t   SetValue($variableIDCode, GetValue($variableIDCode).$value);\r\n\t   Protection_BuildDisplayString($variableIDCode, $variableIDDisplay);\r\n\t}\r\n\r\n\tfunction Protection_ClearDigitFromCode($variableIDCode, $variableIDDisplay) {\r\n\t   if (strlen(GetValue($variableIDCode)) &gt; 0) {\r\n\t   \tSetValue($variableIDCode, substr(GetValue($variableIDCode), 0, -1));\r\n\t\t   Protection_BuildDisplayString($variableIDCode, $variableIDDisplay);\r\n\t   }\r\n\t}\r\n\r\n\tfunction CreateVariable ($name, $type, $parentId, $position=0, $profile=&quot;&quot;, $action=null) {\r\n\t\t$variableId = @IPS_GetObjectIDByIdent($name, $parentId);\r\n\t\tif ($variableId === false) {\r\n \t\t\t$variableId = IPS_CreateVariable($type);\r\n\t\t\tIPS_SetParent($variableId, $parentId);\r\n\t\t\tIPS_SetName($variableId, $name);\r\n\t\t\tIPS_SetIdent($variableId, $name);\r\n\t\t\tIPS_SetPosition($variableId, $position);\r\n  \t\t\tIPS_SetVariableCustomProfile($variableId, $profile);\r\n \t\t\tIPS_SetVariableCustomAction($variableId, $action);\r\n\t\t}\r\n\t\treturn $variableId;\r\n\t}\r\n\r\n?&gt;<\/pre>\n<p>Zus\u00e4tzlich zu dem Script f\u00fcr die <a title=\"Alarmanlage mit Code Ein- und Ausschalten\" href=\"http:\/\/ipsview.brownson.at\/?p=305\">Alarmanlage<\/a>, gibt es hier noch eine Variable Hidden, mit der man die Sichtbarkeit von Bedienelementen steuern kann. Der Wert der Variable ist immer die Umkehrung der Statusvariable.<\/p>\n<p><span style=\"text-decoration: underline;\">Integration in IPSView:<\/span><\/p>\n<p>Im Designer \u00f6ffnet man nun die Seite der View die man mit einer Codeeingabe sch\u00fctzen m\u00f6chte. Ich habe ich als anschauliches Beispiel einfach mal den Floorplan meines Erdgeschosses verwendet:<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerStart.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-327\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerStart-300x166.png\" alt=\"IPSView_ViewProtection_DesignerStart\" width=\"300\" height=\"166\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerStart-200x111.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerStart-300x166.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerStart-1024x569.png 1024w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerStart.png 1302w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Nun platziert man ein Label \u00fcber die komplette Seite und setzt die ID der Variable \u201eHidden\u201c im Property \u201eVariable Versteckt\u201c. Dieses Label sorgt daf\u00fcr, dass man auf der Seite nichts bedienen kann, wenn keine Codeeingabe erfolgt ist. Durch die leichte Transparenz der Hintergrundfarbe sieht man die Steuerelemente im Hintergrund im Client dann noch.<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerBack.png\"><img decoding=\"async\" class=\"alignnone size-thumbnail wp-image-323\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerBack-200x140.png\" alt=\"IPSView_ViewProtection_DesignerBack\" width=\"200\" height=\"140\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerBack-200x140.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerBack-300x211.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerBack.png 956w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a><\/p>\n<p><strong>ACHTUNG:<\/strong> Der Designer beherrscht keine Anzeige von Transparenten Steuerelementen, im Client werden sie allerdings korrekt dargestellt.<\/p>\n<p>\u00dcber dieses Label platziert man nun die Elemente f\u00fcr die Codeeingabe, analog wie es bereits bei der Steuerung der <a title=\"Alarmanlage mit Code Ein- und Ausschalten\" href=\"http:\/\/ipsview.brownson.at\/?p=305\">Alarmanlage<\/a> beschrieben wurde.<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerButton1.png\"><img decoding=\"async\" class=\"alignnone size-thumbnail wp-image-324\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerButton1-200x140.png\" alt=\"IPSView_ViewProtection_DesignerButton1\" width=\"200\" height=\"140\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerButton1-200x140.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerButton1-300x211.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerButton1.png 956w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a> <a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel.png\"><img decoding=\"async\" class=\"alignnone size-thumbnail wp-image-326\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel-200x150.png\" alt=\"IPSView_ViewProtection_DesignerLabel\" width=\"200\" height=\"150\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel-200x150.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel-300x225.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel.png 953w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a><\/p>\n<p>Zus\u00e4tzlich wird hier allerdings bei jedem Element das Property \u201eVariable Versteckt\u201c gesetzt. Diese Fernsteuer Option gew\u00e4hrleistet, dass die Steuerelemente nur sichtbar sind, wenn eine Codeeingabe erforderlich ist.<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerButtonOn.png\"><img decoding=\"async\" class=\"alignnone wp-image-326 size-thumbnail\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel-200x150.png\" alt=\"IPSView_ViewProtection_DesignerButtonOn\" width=\"200\" height=\"150\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel-200x150.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel-300x225.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_DesignerLabel.png 953w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a><\/p>\n<p>Zum Abschluss muss jetzt noch eine Kopie des ToggleButtons zum Ein\/Ausschalten im Bereich der zu sch\u00fctzenden Steuerelemente platziert werden. Dieser ist erforderlich, damit man den Schutz auch wieder aktivieren kann.<\/p>\n<p>Das Bearbeiten der Elemente die sich im Hintergrund (also hinter dem Label das sich \u00fcber die gesamte Seite erstreckt) ist etwas tricky. Am praktikabelsten ist es, wenn man die entsprechenden Elemente markiert und \u00fcber das Kontext Men\u00fc die Option \u201eIn den Hintergrund senden\u201c bzw. \u201eIn den Vordergrund holen\u201c w\u00e4hlt.<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOn.png\"><img decoding=\"async\" class=\"alignnone wp-image-321 size-medium\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOn-300x225.png\" alt=\"IPSView_ViewProtection_ExampleOn\" width=\"300\" height=\"225\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOn-200x150.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOn-300x225.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOn.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOff.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-320\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOff-300x225.png\" alt=\"IPSView_ViewProtection_ExampleOff\" width=\"300\" height=\"225\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOff-200x150.png 200w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOff-300x225.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_ViewProtection_ExampleOff.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c4hnlich dem Vorgehen zum Code gesch\u00fctzten Ein- und Ausschalten einer  [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,6],"tags":[15,14,16,7],"class_list":["post-319","post","type-post","status-publish","format-standard","hentry","category-howto","category-skripte","tag-alarmanlage","tag-code","tag-schuetzen","tag-skript"],"_links":{"self":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319"}],"version-history":[{"count":7,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":397,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/319\/revisions\/397"}],"wp:attachment":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}