V2/Admin.pm untested

filter: Statementstmt 0.0% 0 / 1302 Branchbran 0.0% 0 / 492 Conditioncond 0.0% 0 / 316 MC/DCmcdc 0.0% 0 / 178 Subroutinesub 0.0% 0 / 47 Podpod 0.0% 0 / 39 totaltotal 0.0% 0 / 2374 CC 247 SCAR 73.4
CC
247
Cov
0%
adminField
5112.0
GNFTree
1332.0
importSiteImage
870.0
CRAP 1548.0
1 package FWS::V2::Admin;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6 no warnings 'uninitialized';
7  
8 =head1 NAME
9  
10 FWS::V2::Admin - Framework Sites version 2 internal administration
11  
12 =head1 VERSION
13  
14 Version 1.13091122
15  
16 =cut
17  
18 our $VERSION = '1.13091122';
19  
20  
21 =head1 SYNOPSIS
22  
23 use FWS::V2;
24  
25 #
26 # Create $fws
27 #
28 my $fws = FWS::V2->new();
29  
30  
31 =head1 DESCRIPTION
32  
33 These methods are used by the FWS to perform web based admin features. Most methods here are not for general use and can change at any time, reference these in plugins and element for experimental reasons only.
34  
35 =cut
36  
37  
38 =head1 METHODS
39  
40 These modules are used for FWS admin display and logic. They should not be used outside of the context of FWS admin modules specific to the current build.
41  
42 =cut
43  
44  
45 =head2 runAdminAction
46  
47 Run admin actions. This will be depricated once they are all moved into the FWS display elements.
48  
49 =cut
50  
51 sub runAdminAction {
52 my ( $self ) = @_;
53 if ( $self->isAdminLoggedIn() && !$self->{stopProcessing} ) { $self->_processAdminAction() }
54 return;
55 }
56  
57  
58 =head2 adminPageHeader
59  
60 Return a standard HTML admin header for admin elements that open in new pages.
61  
62 #
63 # Header for an admin page that opens in a new window
64 #
65 $valueHash{html} .= $fws->adminPageHeader(
66 name => 'Page Name in the upper right',
67 rightContent => 'This will show up on the right,' .
68 'usually its a saving widget',
69 title => 'This is title on the left, it will' .
70 'look just like a panel title',
71 icon => 'somethingInTheFWSIconDirectory.png');
72  
73 NOTE: This should only be used in the context of the FWS Administration, and is only here as a reference for modifiers of the admin.
74  
75 =cut
76  
77 sub adminPageHeader {
78 my ( $self, %paramHash ) = @_;
79 my $bgIcon;
80 my $headerHTML = "<div class=\"FWSAdminPageHeader\">";
81 $headerHTML .= "<div class=\"FWSAdminPageHeaderPageTitle\">" . $paramHash{name} . "</div>";
82 $headerHTML .= "<div class=\"FWSAdminPageHeaderTitle\">" . $paramHash{title} . "</div>";
83 $headerHTML .= "<div class=\"FWSAdminPageHeaderContent\">" . $paramHash{rightContent} . "</div>";
84 $headerHTML .= "</div>";
85  
86 return $headerHTML;
87 }
88  
89  
90 =head2 displayAdminLogin
91  
92 Return the HTML used for a default FWS admin login.
93  
94 =cut
95  
96 sub displayAdminLogin {
97 my ( $self, @tabList ) = @_;
98 my $pageId = $self->formValue('p');
99  
100 my $loginForm = "<div class=\"FWSAdminLoginContainer\"><div id=\"FWSAdminLogin\">";
101 $loginForm .= "<form method=\"post\" enctype=\"multipart/form-data\" action=\"" . $self->{scriptName} . "\">";
102  
103 $loginForm .= "<h2>FWS Administrator Login</h2>";
104  
105 $loginForm .= "<div class=\"FWSAdminLoginLeft\"><label for=\"FWSAdminLoginUser\">Username:</label><br/><input type=\"text\" name=\"bs\" id=\"FWSAdminLoginUser\" value=\"" . $self->formValue("bs_hold") . "\" /></div>";
106 $loginForm .= "<div class=\"FWSAdminLoginRight\"><label for=\"FWSAdminLoginPassword\">Password:</label><br/><input id=\"FWSAdminLoginPassword\" type=\"password\" name=\"l_password\" /></div>";
107  
108 $loginForm .= "<div class=\"clear\"></div>";
109  
110 $loginForm .= "<input class=\"FWSAdminLoginButton\" type=\"submit\" title=\"Login\" value=\"Login\" />";
111  
112 $loginForm .= "<input type=\"hidden\" name=\"p\" value=\"" . $self->{adminURL} . "\"/>";
113 $loginForm .= "<input type=\"hidden\" name=\"session\" value=\"" . $self->formValue("session") . "\"/>";
114 $loginForm .= "<input type=\"hidden\" name=\"id\" value=\"" . $self->safeQuery( $self->formValue( "id" ) ) . "\"/>";
115 $loginForm .= "<input type=\"hidden\" id=\"s\" name=\"s\" value=\"" . $self->formValue("s") . "\"/>";
116  
117 $loginForm .= "</form>";
118 $loginForm .= "</div>";
119  
120 $loginForm .= "<div class=\"FWSAdminLoginLegal\">Powered by Framework Sites v" . $self->{FWSVersion} . "</div>";
121  
122 $loginForm .= "</div></div>";
123  
124 return $self->printPage( content => $loginForm, head => $self->_minCSS() );
125 }
126  
127  
128  
129 =head2 editField
130  
131 Some legacy fields still use this render drop downs. For new code do not use this.
132  
133 =cut
134  
135 sub editField {
136 my ( $self, %paramHash ) = @_;
137  
138 #
139 # if elementId is not passed lets use the one was stored just before the eval was ran
140 # this will be undocumented that you can set it... not sure if will come up for security or cross refrenced stuff
141 # but it won't need coding if it makes sense later
142 #
143 $paramHash{elementId} ||= $self->formValue( 'FWS_elementId' );
144  
145 #
146 # set context of the params to match the default interal stuff it will need
147 #
148 if ( $paramHash{guid} ) {
149 $paramHash{ajaxUpdateTable} = 'data';
150 $paramHash{ajaxUpdateGUID} = $paramHash{guid};
151 $paramHash{updateType} = $paramHash{elementId};
152 $paramHash{pageAction} = $paramHash{elementId};
153 }
154  
155 #
156 # Set the value
157 #
158 if ( $paramHash{fieldValue} eq '' && $paramHash{guid} ) {
159 my %dataHash = $self->dataHash( guid => $paramHash{guid} );
160 $paramHash{fieldValue} = $dataHash{$paramHash{fieldName}};
161 }
162  
163 $paramHash{guid} = $paramHash{fieldName};
164  
165 return $self->adminField(%paramHash);
166 }
167  
168  
169 =head2 tabs
170  
171 Return jQueryUI tab html. The tab names, tab content, tinyMCE editing field name, and any javascript for the tab onclick is passed as arrays to the method.
172  
173 #
174 # add the data to the tabs and panels to the HTML
175 #
176 $valueHash{html} .= $self->tabs(
177 id => 'theIdOfTheTabContainer',
178 tabs => [@tabs],
179 tabContent => [@tabContent],
180 tabJava => [@tabJava],
181  
182 # html and file tab support
183 tabType => [@tabType], # file, html or leave empty for standard panel
184 # setting type will overwrite content and java provided
185  
186 tabFields => [@tabFields], # field your updating
187  
188 guid => 'someGUID', # guid your updating
189  
190 # optional if your talking to a non-data table
191 tabUpdateType => [@tabUpdateType], # defaults to AJAXExt
192 table => 'data', # defaults to data
193  
194 # for file type only (required)
195 currentFile => [@currentFile], #
196 );
197  
198 NOTE: This should only be used in the context of the FWS Administration, and is only here as a reference for modifiers of the admin. In future versions this will be replaced with a hash array style paramater to make this less cumbersome, but this will be avaiable for legacy controls.
199  
200 =cut
201  
202 sub tabs {
203 my ( $self, %paramHash ) = @_;
204  
205 #
206 # this will be the counter we will use for inique IDs for each tab for referencing
207 #
208 my $tabCount = 0;
209  
210 #
211 # seed our tab html and the div html that will hold the content
212 #
213 my $tabDivHTML;
214 my $tabHTML = "<div id=\"" . $paramHash{id} . "\" class=\"FWSTabs tabContainer ui-tabs ui-widget ui-widget-content ui-corner-all\"><ul class=\"tabList ui-tabs ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all\">";
215  
216 while (@{$paramHash{tabs}}) {
217 my $tabJava = shift( @{$paramHash{tabJava}} );
218 my $tabContent = shift( @{$paramHash{tabContent}} );
219 my $tabName = shift( @{$paramHash{tabs}} );
220 my $fieldName = shift( @{$paramHash{tabFields}} );
221 my $tabType = shift( @{$paramHash{tabType}} );
222 my $tabUpdateType = shift( @{$paramHash{tabUpdateType}} );
223 my $currentFile = $self->urlEncode( shift( @{$paramHash{currentFile}} ) );
224  
225 #
226 # set the default
227 #
228 $tabUpdateType ||= 'AJAXExt';
229  
230 #
231 # pass all the info in as the id so we can save it later
232 #
233 my $editorName = $paramHash{guid} . "_v_" . $fieldName . "_v_" . $paramHash{table} . "_v_" . $tabUpdateType;
234  
235 #
236 # tab type overwrites tabJava and tabContent!
237 #
238 if ( $tabType eq 'file' ) {
239 $tabContent = "<div id=\"dataEdit" . $fieldName . "\">Loading...</div>";
240 $tabJava = "if(\$('#dataEdit" . $fieldName . "').html().length < 50) {\$('#dataEdit" . $fieldName . "').FWSAjax({queryString: '" . $self->{queryHead} . "p=fws_fileManager&current_file=" . $currentFile . "&field_update_type=" . $tabUpdateType . "&field_table=" . $paramHash{table} . "&field_name=" . $fieldName . "&guid=" . $paramHash{guid} . "',showLoading: false});}";
241 }
242  
243 if ( $tabType eq 'html' ) {
244 $tabContent = "<div name=\"" . $fieldName . "\" id=\"" . $editorName . "\" class=\"HTMLEditor\" style=\"width:100%;height:445px;\">" . $tabContent . "</div><div style=\"display:none;\" id=\"" . $paramHash{guid} . "_v_" . $fieldName . "_v_StatusNote\"></div>";
245 }
246  
247 #
248 # this is the connector between the tab and its HTML
249 #
250 my $tabHRef = $paramHash{id} . "_" . $tabCount . "_" . $self->createPassword( composition => 'qwertyupasdfghjkzxcvbnmQWERTYUPASDFGHJKZXCVBNM', lowLength => 6, highLength => 6 );
251  
252 #
253 # if tiny mce is being used on a tab, lets light it up per the clicky
254 # also tack on any tabJava we had passed to us
255 #
256 my $javaScript = "FWSCloseMCE();";
257 $javaScript .= "if ( typeof(tinyMCE) != 'undefined' ) { tinyMCE.execCommand('mceAddControl', false, '" . $editorName . "'); }";
258 $javaScript .= "if ( typeof(\$.modal) != 'undefined' ) { \$.modal.update(); }";
259 $javaScript .= "if ( typeof(\$.modal) != 'undefined' ) { \$.modal.update(); }";
260 $javaScript .= $tabJava;
261 $javaScript .= "return false;";
262  
263 #
264 # flag we are on the first one!... we want to hide the content areas if we are not
265 #
266 my $hideMe;
267 if ( $tabCount > 0 ) { $hideMe = " ui-tabs-hide" }
268  
269 #
270 # add to the tab LI and the HTML we will put below for each tab
271 #
272 $tabHTML .= "<li class=\"tabItem tabItem ui-state-default ui-corner-top ui-state-hover\"><a onclick=\"" . $javaScript . "\" href=\"#" . $tabHRef . "\">" . $tabName . "</a></li>";
273 $tabDivHTML .= "<div id=\"" . $tabHRef . "\" class=\"ui-tabs-panel ui-widget-content ui-corner-bottom" . $hideMe . "\">" . $tabContent . "</div>";
274  
275 #
276 # add another tabCount to make our next tab unique ( plus a unique 6 char key )
277 #
278 $tabCount++;
279 }
280  
281 #
282 # the tabs need this jquery ui stuff to work. lets make sure they are here if they aren't laoded already
283 #
284 $self->jqueryEnable( 'ui-1.8.9' );
285 $self->jqueryEnable( 'ui.widget-1.8.9' );
286 $self->jqueryEnable( 'ui.tabs-1.8.9' );
287 $self->jqueryEnable( 'ui.fws-1.8.9' );
288  
289 #
290 # return the tab content closing the ul and div we started in tabHTML
291 #
292 return $tabHTML . '</ul>' . $tabDivHTML . '</div>';
293 }
294  
295  
296 =head2 importSiteImage
297  
298 Unpack a agnostic DB and File administration packages via FWS administration distrubuted by framworksites.com.
299  
300 =cut
301  
302 sub importSiteImage {
303 my ( $self, %paramHash ) = @_;
304  
305 my $image = $paramHash{image};
306 my $imageFile = $paramHash{imageFile};
307 my $imageURL = $paramHash{imageURL};
308 my $tableList = $paramHash{tableList};
309 my $deleteBeforeImport = $paramHash{deleteBeforeImport};
310 my $filesOnly = $paramHash{filesOnly};
311 my $dataOnly = $paramHash{dataOnly};
312 my $postField = $paramHash{postField};
313  
314 my $importReturn;
315 my %importTable;
316  
317 #
318 # create a import file and start writing to it depending onhow we got the file in
319 #
320 my $importFile = $self->fileSecurePath() . "/import_" . $self->formatDate( format => 'number' ) . ".fws";
321  
322 open ( my $IFILE, ">", $importFile );
323  
324 #
325 # we have an image string save it off so we can process it with the file handle
326 #
327 if ( $image ) { print $IFILE $image }
328  
329 #
330 # if we got a URL get it!
331 #
332 if ( $imageURL ) {
333 require LWP::UserAgent;
334 my $browser = LWP::UserAgent->new();
335 my $response = $browser->get( $imageURL );
336 if (!$response->is_success ) { return "Error connecting to the FWS Module Server was found: " . $response->status_line }
337 print $IFILE $response->content;
338 }
339  
340 #
341 # if it is ac existing site, use the admin password already there. if not leave it blank so it won't allow logins
342 #
343 my ( $siteActive, $siteGUID, $homeGUID ) = @{$self->runSQL( SQL => "select 1,site_guid,home_guid from site where sid = '" . $paramHash{newSID} . "'" )};
344  
345 #
346 # get the tables we are going to import and set them to on.
347 #
348 my @tables = split( ',', $tableList );
349 while ( @tables ) {
350 my $theTable = shift( @tables );
351 $importTable{$theTable} = 1;
352 }
353  
354 #
355 # read textImage if that was handed to us
356 #
357 if ( $postField ) {
358 my $bytesread;
359 my $buffer;
360 while ( $bytesread = read( $self->formValue( $postField ), $buffer, 1024 ) ) {
361 $buffer =~ s/[\x0A\x0D]+/\n/g;
362 print $IFILE $buffer;
363 }
364 }
365  
366 #
367 # read file if that was handed to us
368 #
369 if ( $imageFile ) {
370 open ( my $FILE, "<", $imageFile );
371 while ( my $inputLine = <$FILE> ) { print $IFILE $inputLine . "\n" };
372 close $FILE;
373 }
374  
375  
376 #
377 # close the import file down so we can reopen it for processing
378 #
379 close $IFILE;
380  
381 #
382 # double check if the site is valid, in case this is ran from a script
383 # most importanly we want to make sure the site_guid isnt already there
384 #
385  
386 #
387 # if we are talking aout the admin import, or an elementOnly import let this ride
388 #
389 my $validSite = $self->_isValidSID( $paramHash{newSID} );
390  
391  
392 #
393 # set a flag for elementOnly
394 #
395 my $elementOnly = 0;
396 if ( ( split(/\n/, $image ) )[0] eq "ELEMENT ONLY" ) {
397 $importReturn = "Importing element to existing site ID:" . $paramHash{newSID};
398 $elementOnly = 1;
399 }
400  
401 if ( $validSite && $paramHash{newSID} ne 'zipcode' && $paramHash{newSID} ne 'admin' && !$elementOnly) { return " " . $validSite . " No import was performed." }
402  
403 #
404 # if it is an element Only import, make sure the site_guid is valid
405 #
406 if ( ( $elementOnly && !$siteActive ) || !$paramHash{newSID} ) { return "The FWS File is an element import file, and '" . $paramHash{newSID} . "' is not a valid Site ID. No element import was performed." }
407  
408 if ( !-s $importFile ) { return "The FWS File is invalid. No import was performed." }
409  
410 #
411 # get the site GUID we are importing to
412 #
413 $siteGUID ||= $self->createGUID( 's' );
414  
415 #
416 # if this is an fws import we need the fws id and import away
417 #
418 if ( $paramHash{newSID} eq 'fws' ) {
419 $siteGUID = $self->safeSQL( $self->fwsGUID() );
420  
421 #
422 # blow away all the stuff the is FWS so we can come in fresh
423 #
424 if ( $paramHash{removeCore} ) {
425 $self->runSQL( SQL => "delete from data where guid like 'f%'" );
426 $self->runSQL( SQL => "delete from element where guid like 'f%'" );
427 $self->runSQL( SQL => "delete from guid_xref where site_guid = '" . $self->safeSQL( $siteGUID ) . "'" );
428 $self->runSQL( SQL => "delete from data_cache where guid like 'f%'" );
429 }
430 }
431  
432 #
433 # decompress and process
434 #
435 my $fileName;
436 my $fileReading;
437 my %tableSchema;
438 my $keepAliveCount = 0;
439 $paramHash{keepAlive} ||= 0;
440  
441  
442 open( my $READ_FILE, "<", $importFile );
443  
444 while (my $line = <$READ_FILE>) {
445 $line =~ s/\n$//g;
446 $keepAliveCount++;
447 if ( $line =~ /^FILE_END\|/ && !$dataOnly ) {
448 #
449 # get just the directory so we can make the dir in case it does not exist already
450 #
451 my $fileDir = $self->{filePath} . $fileName;
452 my @splitDir = split( /\//, $fileDir );
453 pop(@splitDir);
454 my $justDirectory = join( "/", @splitDir );
455  
456 #
457 # make sure nothing dangrous is in the dir
458 #
459 $justDirectory =~ s/\/\//\//sg;
460  
461 #
462 # if we are not doing an element only, or the file starts with /admin save the file
463 #
464 if ( !$self->formValue( 'elementOnly' ) || $fileName =~ /^\/admin\// ) {
465 #
466 # create the directory to make sure its good
467 #
468 $self->makeDir( $justDirectory );
469  
470 #
471 # save the file to that directory
472 #
473 $self->saveEncodedBinary( $self->{filePath} . $fileName, $fileReading );
474 }
475  
476 #
477 # reset so when we come around again we will no we are done.
478 #
479 $fileName = '';
480 $fileReading = '';
481 }
482  
483 #
484 # if we have a file name, we are currenlty looking for a
485 # file. eat those lines up and stick them in a diffrent var
486 #
487 elsif ( $fileName ) { $fileReading .= $line . "\n" }
488  
489 #
490 # if this is a start of a file, lets get it set up and
491 # define the file name, the next time we go around we
492 # will be looking at the base 64
493 #
494 elsif ( $line =~ /^FILE\|/ && !$dataOnly ) {
495 my @fileNameArray = split(/\|/,$line);
496 $fileName = $fileNameArray[1];
497 $fileName =~ s/#FWSSiteGUID#/$siteGUID/sg;
498 }
499  
500 #
501 # ALLLRIGHTY, this isn't a file, lets process it like it
502 # it is a normal database row that needs to be processed
503 #
504 else {
505 my @data = split( /\|/, $line );
506  
507 my $tableName = shift( @data );
508  
509 my @fieldList = split( ',', $tableSchema{$tableName} );
510 my $numberOfFields = $#fieldList;
511  
512 #
513 # if we havn't seen this table before that means its a schema
514 #
515 if ( !defined $tableSchema{$tableName} ) { $tableSchema{$tableName} = shift(@data) }
516 else {
517 my $cleanData;
518 my $dataCount = 0;
519 my $skipComma = 1;
520 my $skipInsert = 0;
521 my $fieldNames = $tableSchema{$tableName};
522  
523 for( my $dataCount=0; $dataCount <= $numberOfFields; $dataCount++ ) {
524  
525 #
526 # decode the data and flip stuf arround that needs to be groomed
527 #
528 $data[$dataCount] = $self->urlDecode( $data[$dataCount] );
529
530 #
531 # Set the new sid
532 #
533 if ( $tableName eq 'site' && $fieldList[$dataCount] eq 'sid' ) { $data[$dataCount] = $paramHash{newSID} }
534  
535 if ( $tableName eq 'site' && $fieldList[$dataCount] eq 'site_guid' ) {
536 #
537 # we need the admin guid for this install.
538 #
539 my ( $parentSID ) = @{$self->runSQL( SQL => "select guid from site where sid='admin'" )};
540 $data[$dataCount] = $parentSID;
541 }
542  
543 #
544 # if we are importing stuff from the admin, we need these to be fws
545 #
546 if ( $paramHash{newSID} eq 'admin' ) {
547 if ( $tableName eq 'data' && $fieldList[$dataCount] eq 'site_guid' ) { $data[$dataCount] = 'fws'}
548 if ( $tableName eq 'guid_xref' && $fieldList[$dataCount] eq 'site_guid' ) { $data[$dataCount] = 'fws'}
549 }
550  
551  
552 #
553 # if we hvan't already skip the first comma, and then add the field
554 #
555 if (!$skipComma) { $cleanData .= ',' }
556  
557  
558 #
559 # clean and format the data from the import storage
560 #
561 $data[$dataCount] = $self->_convertImportTags( content => $data[$dataCount], siteGUID => $siteGUID, homeGUID => $homeGUID );
562  
563 #
564 # convert safe text export back to the storable version
565 #
566 if ( $fieldList[$dataCount] eq 'extra_value' ) {
567 my @splitExtra = split(/\|/,$data[$dataCount]);
568 my %extraHash;
569 while (@splitExtra) {
570 my $field = shift @splitExtra;
571 my $value = shift @splitExtra;
572 $value = $self->urlDecode( $value );
573 $value = $self->_convertImportTags( content => $value, siteGUID => $siteGUID, homeGUID => $homeGUID );
574 $extraHash{$self->urlDecode( $field )} = $value;
575 }
576 use Storable qw(nfreeze thaw);
577 $data[$dataCount] = nfreeze(\%extraHash);
578 }
579  
580 #
581 # add to the insert statement string
582 #
583 if ( $data[$dataCount] =~ /^null$/i ) { $cleanData .= 'null' }
584 else { $cleanData .= "'" . $self->safeSQL( $data[$dataCount] ) . "'" }
585  
586 $skipComma = 0;
587  
588 }
589  
590 #
591 # process what we collected from th loop
592 #
593  
594 #
595 # lets check to make sure we are only going to do elements if we are element only
596 #
597 if ( ( $tableName ne "element" && $self->formValue( "elementOnly" ) ) ) {
598 $skipInsert = 1;
599 }
600  
601 #
602 # only add the data to the DB if the we are not set to fileOnly mode,
603 # and if we are not on special
604 # fields that do not have.
605 #
606 if (!$skipInsert && !$filesOnly ) {
607  
608 my $siteCSS;
609 my $siteJavaScript;
610 my $pageJavaScript;
611 my $pageCSS;
612 $self->runSQL( SQL => "insert into " . $tableName . " (" . $fieldNames . ") values (" . $cleanData . ")" );
613  
614 }
615 }
616 }
617 if ( $keepAliveCount > $paramHash{keepAlive} ) {
618 $keepAliveCount = 0;
619 if ( $paramHash{keepAlive} ) { print " ." }
620 }
621 }
622 close $READ_FILE;
623 return $importReturn;
624 }
625
626  
627 =head2 adminField
628  
629 Return an edit field or field block for the FWS Admin. The adminField method is a very configurable tool used by the FWS administration maintainers.
630  
631 #
632 # Create a admin edit field
633 #
634 $valueHash{html} .= $fws->adminField( %paramHash );
635  
636 NOTE: This should only be used in the context of the FWS Administration, and is only here as a reference for modifiers of the admin.
637  
638 Passable Keys:
639 fieldType
640 fieldName
641 fieldValue
642 fieldOptions
643 unilingual: [1|0]
644 ajaxUpdateGUID
645 ajaxUpdateParentId
646 id
647 class
648 style
649 onSaveComplete
650 updateType
651 guid
652 onKeyDown
653 note
654 afterFieldHTML
655  
656 =cut
657  
658 sub adminField {
659 my ( $self, %paramHash ) = @_;
660  
661 #
662 # for language replication fields, hold the array here so we can use it clean
663 #
664 my %origHash = %paramHash;
665  
666 #
667 # set the id if not already set or if we going to use ajax, lets make a
668 # new id so we don't get dups from bad programming
669 #
670 if ( !$paramHash{id} || $paramHash{updateType} ) { $paramHash{id} = $paramHash{fieldName} }
671  
672 #
673 # make the guid for ajax unique if needed
674 #
675 $paramHash{guid} ||= $paramHash{fieldName};
676  
677 #
678 # Set the uniqueId to something other than guyid if its passed, for save icon references
679 #
680 $paramHash{uniqueId} ||= $paramHash{fieldName};
681  
682 #
683 # if these are blank, add them to the unique to make it more unique
684 #
685 if ( $paramHash{ajaxUpdateGUID} ) { $paramHash{uniqueId} .= "_" . $paramHash{ajaxUpdateGUID} }
686 if ( $paramHash{ajaxUpdateParentId} ) { $paramHash{uniqueId} .= "_" . $paramHash{ajaxUpdateParentId} }
687  
688 #
689 # if we are talking about a date, we are recieving it in SQL format, lets flip it real quicik
690 # before we display it
691 #
692 if ( $paramHash{fieldType} eq 'dateTime' && $paramHash{fieldValue} ne '') {
693  
694 #
695 # convert from SQL format and spin it around for normal US date formats
696 #
697 if ( $paramHash{dateFormat} =~ /(sql|)/i ) {
698 my ( $year, $month, $day, $hour, $minute, $second ) = split( /\D/, $paramHash{fieldValue} );
699 $paramHash{fieldValue} = $month . "-" . $day . "-" . $year . " " . $hour . ":" . $minute . ":" . $second;
700 }
701 }
702  
703 #
704 # if we are talking about a date, we are recieving it in SQL format, lets flip it real quicik
705 # before we display it
706 #
707 if ( $paramHash{fieldType} eq 'date' && $paramHash{fieldValue} ne '' ) {
708  
709 #
710 # convert from SQL format and spin it around for normal US date formats
711 #
712 if ( $paramHash{dateFormat} =~ /sql/i || !$paramHash{dateFormat} ) {
713 my ( $year, $month, $day ) = split( /\D/, $paramHash{fieldValue} );
714 $paramHash{fieldValue} = $month . "-" . $day . "-" . $year;
715 }
716  
717 #
718 # convert from number format to normal dates so the picker will love it
719 #
720 if ( $paramHash{dateFormat} =~ /number/i ) {
721 my $year = substr( $paramHash{fieldValue}, 0, 4 );
722 my $month = substr( $paramHash{fieldValue}, 4, 2 );
723 my $day = substr( $paramHash{fieldValue}, 6, 2 );
724 $paramHash{fieldValue} = $month . "-" . $day . "-" . $year;
725 }
726 }
727  
728 #
729 # this is the js needed to copy the date field to the SQL compatable hidden field
730 #
731  
732 my $copyToHidden = "\$('#" . $paramHash{uniqueId} . "_ajax').val(\$('#" . $paramHash{uniqueId} . "').val());";
733  
734 if ( $paramHash{fieldType} eq 'date' ) {
735 $copyToHidden = "if (document.getElementById('" . $paramHash{uniqueId} . "\').value != '') {var dateSplit=document.getElementById('" . $paramHash{uniqueId} . "\').value.split(/\\D/);while(dateSplit[1].length &lt; 2) { dateSplit[1] = '0'+dateSplit[1];}while(dateSplit[0].length &lt; 2) { dateSplit[0] = '0'+dateSplit[0];}document.getElementById('" . $paramHash{uniqueId} . "_ajax').value=dateSplit[2]+'-'+dateSplit[0]+'-'+dateSplit[1];}else {document.getElementById('" . $paramHash{uniqueId} . "_ajax').value='';}";
736 }
737  
738 if ( $paramHash{fieldType} eq 'dateTime' ) {
739 $copyToHidden = "if (document.getElementById('" . $paramHash{uniqueId} . "\').value != '') {var dateSplit=document.getElementById('" . $paramHash{uniqueId} . "\').value.split(/\\D/);while(dateSplit[1].length &lt; 2) { dateSplit[1] = '0'+dateSplit[1];}while(dateSplit[0].length &lt; 2) { dateSplit[0] = '0'+dateSplit[0];}document.getElementById('" . $paramHash{uniqueId} . "_ajax').value=dateSplit[2]+'-'+dateSplit[0]+'-'+dateSplit[1]+' '+dateSplit[3]+':'+dateSplit[4]+':'+dateSplit[5];}else {document.getElementById('" . $paramHash{uniqueId} . "_ajax').value='';}";
740 }
741  
742 #
743 # set the style if we have to something to give
744 #
745 my $styleHTML;
746 if ( $paramHash{style} ) { $styleHTML = " style=\"" . $paramHash{style} . "\"" }
747  
748 #
749 # Seed the save JS, we will build on this depending on what we have to work with
750 #
751 my $AJAXSave;
752  
753 #
754 # radio boxes have there own transfer method
755 #
756 if ( $paramHash{fieldType} ne "radio" && $paramHash{fieldType} ne 'date' ) {
757 $AJAXSave .= $copyToHidden;
758 }
759  
760 #
761 # seed the onSaveJS, we will seed this also and depdningon what we are doing, we might
762 # need to do different onSaveJS functions
763 #
764 my $onSaveJS;
765  
766 #
767 # if your a text area, update the text
768 #
769 if ( $paramHash{updateType} && $paramHash{fieldType} eq "textArea" ) {
770 $onSaveJS .= "\$('#" . $paramHash{uniqueId} . "_status').css('visibility', 'hidden');"
771 }
772  
773 #
774 # if your a password, update the text
775 #
776 if ( $paramHash{updateType} && $paramHash{fieldType} eq "password") {
777 $onSaveJS .= "\$('#" . $paramHash{uniqueId} . "_passwordStrong').hide();"
778 }
779  
780 #
781 # everyone gets the spinny
782 #
783 my $imageID;
784 if ( $paramHash{updateType} ) {
785 $imageID = "'#" . $paramHash{uniqueId} . "_img'";
786 $onSaveJS .= "\$(" . $imageID . ").attr('src','" . $self->{fileFWSPath} . "/saved.gif');";
787 $AJAXSave .= "\$(" . $imageID . ").attr('src','" . $self->loadingImage() . "');";
788 }
789  
790 #
791 # after the save is complete run this javascript
792 #
793 if ( $paramHash{onSaveComplete} ) {
794 $onSaveJS .= $paramHash{onSaveComplete};
795 }
796  
797 #
798 # tack in the onSave it was populated
799 #
800 if ( $onSaveJS ) { $onSaveJS = ",onSuccess: function() {" . $onSaveJS . "}" }
801  
802 #
803 # the save everyone uses
804 #
805 if ( $paramHash{updateType} ) {
806 if ( $paramHash{updateType} eq "AJAXUpdate" || $paramHash{updateType} eq "AJAXExt" ) {
807 $AJAXSave .= "\$('<div></div>').FWSAjax({queryString:'s=" . $self->{siteId} . "&p=fws_dataEdit&guid=" . $paramHash{ajaxUpdateGUID} . "&parent=" . $paramHash{ajaxUpdateParentId} . "&table=" . $paramHash{ajaxUpdateTable} . "&field=" . $paramHash{fieldName} . "&value='+encodeURIComponent(\$('#" . $paramHash{uniqueId} . "_ajax').val())+'&pageAction=" . $paramHash{updateType} . "'" . $onSaveJS . ",showLoading:false});";
808 }
809 else {
810 #TODO Validate if this other updateType ajax is even being used anymore
811 $AJAXSave .= "\$('<div></div>').FWSAjax({queryString:'s=" . $self->{siteId} . "&guid=" . $paramHash{ajaxUpdateGUID} . "&parent=" . $paramHash{ajaxUpdateParentId} . "&field=" . $paramHash{fieldName} . "&value='+encodeURIComponent(\$('#" . $paramHash{uniqueId} . "_ajax').val())+'&pageAction=" . $paramHash{updateType} . "&p=" . $paramHash{updateType} . "'" . $onSaveJS . ",showLoading:false});";
812 }
813 }
814  
815 #
816 # if this is a date fields, lets wrap this in the conditional not to save unless its groovy
817 #
818 if ( $paramHash{fieldType} eq 'date' || $paramHash{fieldType} eq 'dateTime' ) {
819 my $reformatJS;
820 $reformatJS .= "if (\$('" . $paramHash{uniqueId} . "_ajax').val() != '') {";
821 if ( $paramHash{dateFormat} =~ /number/i ) {
822 $reformatJS .= "var cleanDate;cleanDate = document.getElementById('" . $paramHash{uniqueId} . "_ajax').value.replace(/\\D/g,'');";
823 $reformatJS .= "\$('#" . $paramHash{uniqueId} . "_ajax').val(cleanDate);";
824 }
825 $reformatJS .= '}';
826  
827 $AJAXSave = $copyToHidden . "var dateSplit=document.getElementById('" . $paramHash{uniqueId} . '_ajax\').value.split(/\\D/);if (document.getElementById(\'' . $paramHash{uniqueId} . '_ajax\').value == \'\' || (dateSplit[0].length==4 &amp;&amp; dateSplit[1] &gt; 0 &amp;&amp; dateSplit[1] &lt; 13 &amp;&amp; dateSplit[2] &gt; 0 &amp;&amp; dateSplit[2] &lt; 32 )) { '. $reformatJS . $AJAXSave . '}';
828 }
829  
830 #
831 # change all carrage returns to safe ones that are compatable with ajax calls
832 # only beat up the value field if we are talking about a value that will be injected into an element. otherwise leave it alone
833 # because we might be passing some sweet stuff to it that will have raw html
834 #
835 if ( $paramHash{fieldType} ) {
836 $paramHash{fieldValue} =~ s/\n/&#10;/sg;
837 $paramHash{fieldValue} =~ s/\r//sg;
838 $paramHash{fieldValue} =~ s/"/&quot;/sg;
839 }
840  
841 #
842 # lets starting building the actual fieldHTML we will return
843 # EVERYONE gets the hidden ajax guid
844 #
845 my $fieldHTML = "<input type=\"hidden\" name=\"" . $paramHash{uniqueId} . "_ajax\" id=\"" . $paramHash{uniqueId} . "_ajax\"/>";
846  
847 #
848 # textArea starter with hidden save message only if we are going to update it
849 #
850 if ( $paramHash{updateType} && $paramHash{fieldType} eq "textArea") {
851 $fieldHTML .= "<div id=\"" . $paramHash{uniqueId} . "_status\" style=\"color:#FF0000;visibility:hidden;\">";
852 $fieldHTML .= "<img alt=\"save\" src=\"" . $self->{fileFWSPath} . "/saved.gif\" style=\"border:0pt none;\" id=\"" . $paramHash{uniqueId} . "_img\" onclick=\"" . $AJAXSave . "\"/>";
853 $fieldHTML .= "&nbsp;Your content has not been saved";
854 $fieldHTML .= "</div>";
855 }
856  
857 #
858 # text/password
859 #
860 if ( $paramHash{fieldType} =~ /^(text|password)$/ ) {
861 $fieldHTML .= "<input type=\"" . $paramHash{fieldType} . "\" name=\"" . $paramHash{fieldName} . "\" size=\"60\"" . $styleHTML . " class=\"FWSFieldText " . $paramHash{class} . "\" value=\"" . $paramHash{fieldValue} . "\"";
862 }
863  
864 #
865 # currency,date and number
866 #
867 if ( $paramHash{fieldType} eq 'date' ) {
868 $self->jqueryEnable( 'ui-1.8.9' );
869 $self->jqueryEnable( 'ui.datepicker-1.8.9' );
870 $paramHash{class} .= ' FWSDatePicker';
871 }
872  
873 #
874 # color picker
875 #
876 if ( $paramHash{fieldType} eq 'color') {
877 $paramHash{class} .= " FWSColorPicker";
878 }
879  
880 #
881 # datetime
882 #
883 if ( $paramHash{fieldType} eq 'dateTime') {
884 $self->jqueryEnable( 'ui-1.8.9' );
885 $self->jqueryEnable( 'ui.widget-1.8.9' );
886 $self->jqueryEnable( 'ui.mouse-1.8.9' );
887 $self->jqueryEnable( 'ui.datepicker-1.8.9' );
888 $self->jqueryEnable( 'ui.slider-1.8.9' );
889 $self->jqueryEnable( 'timepickr-0.9.6' );
890 $paramHash{class} .= " FWSDateTime";
891 }
892  
893 if ( $paramHash{fieldType} =~ /^(currency|number|date|color|dateTime)$/ ) {
894  
895 if ( $paramHash{fieldType} eq 'color' ) { $styleHTML = " style=\"background-color: #" . $paramHash{fieldValue} . "\""; }
896  
897 if ( $paramHash{fieldType} eq 'dateTime' ) {
898 $fieldHTML .= "<input type=\"text\" name=\"" . $paramHash{fieldName} . "\" size=\"20\"" . $styleHTML . " class=\"" . $paramHash{class} . "\" value=\"" . $paramHash{fieldValue} . "\"";
899 }
900 else {
901 $fieldHTML .= "<input type=\"text\" name=\"" . $paramHash{fieldName} . "\" size=\"10\"" . $styleHTML . " class=\"" . $paramHash{class} . "\" value=\"" . $paramHash{fieldValue} . "\"";
902 }
903  
904 #
905 # only allow numbers and such
906 #
907 $paramHash{onKeyDown} .= "var keynum; if(window.event) { keynum = event.keyCode } else if(event.which) {";
908 $paramHash{onKeyDown} .= "keynum = event.which };";
909 $paramHash{onKeyDown} .= "if ((";
910 $paramHash{onKeyDown} .= "keynum&lt;48 || keynum&gt;105 || (keynum&gt;57 &amp;&amp; keynum&lt;95)";
911 $paramHash{onKeyDown} .= ")";
912  
913 #
914 # if I'm a color let people pick a-f
915 #
916 if ( $paramHash{fieldType} eq 'color' ) {
917 $paramHash{onKeyDown} .= " &amp;&amp; keynum != 65 &amp;&amp; keynum != 66 &amp;&amp; keynum != 67 &amp;&amp; keynum != 68 &amp;&amp; keynum != 69 &amp;&amp; keynum != 70 ";
918 }
919 else {
920 #
921 # keypad and number: -
922 #
923 $paramHash{onKeyDown} .= " &amp;&amp; keynum != 45 &amp;&amp; keynum != 109 ";
924  
925 #
926 # keypad: .
927 #
928 $paramHash{onKeyDown} .= " &amp;&amp; keynum != 45 &amp;&amp; keynum != 110 ";
929 }
930  
931 $paramHash{onKeyDown} .= " &amp;&amp; keynum!=46 &amp;&amp; keynum!=189 &amp;&amp; keynum!=37 &amp;&amp; keynum!= 39 &amp;&amp; keynum!= 35 &amp;&amp; keynum!= 36 &amp;&amp; keynum!=8 &amp;&amp; keynum!=9 &amp;&amp; keynum!=190) { return false }";
932  
933 }
934  
935 #
936 # dropDown
937 #
938 if ( $paramHash{fieldType} eq "dropDown" ) {
939 $fieldHTML .= "<select name=\"" . $paramHash{fieldName} . "\"" . $styleHTML . " class=\"" . $paramHash{class} . "\"";
940 }
941  
942 if ( $paramHash{fieldType} eq "birthday" ) {
943  
944 #
945 # onchange bday js
946 #
947 my $bdayOnchange = "if (!isNaN(\$('#" . $paramHash{uniqueId} . "_year').val()) && !isNaN(\$('#" . $paramHash{uniqueId} . "_day').val()) && !isNaN(\$('#" . $paramHash{uniqueId} . "_month').val())) { \$('#" . $paramHash{uniqueId} . "_ajax').val(\$('#" . $paramHash{uniqueId} . "_year').val()+'-'+\$('#" . $paramHash{uniqueId} . "_month').val()+'-'+\$('#" . $paramHash{uniqueId} . "_day').val());}";
948 #
949 # month
950 #
951 $fieldHTML .= '<select class="FWSInputField" id="' . $paramHash{uniqueId} . '_month" name="' . $paramHash{uniqueId} . '_month" onchange="' . $bdayOnchange . '">';
952 $fieldHTML .= '<option>- Month -</option>';
953 $fieldHTML .= '<option value="01">January</option>';
954 $fieldHTML .= '<option value="02">February</option>';
955 $fieldHTML .= '<option value="03">March</option>';
956 $fieldHTML .= '<option value="04">April</option>';
957 $fieldHTML .= '<option value="05">May</option>';
958 $fieldHTML .= '<option value="06">June</option>';
959 $fieldHTML .= '<option value="07">July</option>';
960 $fieldHTML .= '<option value="08">August</option>';
961 $fieldHTML .= '<option value="09">September</option>';
962 $fieldHTML .= '<option value="10">October</option>';
963 $fieldHTML .= '<option value="11">November</option>';
964 $fieldHTML .= '<option value="12">December</option>';
965 $fieldHTML .= '</select>';
966  
967 #
968 # Day
969 #
970 $fieldHTML .= '<select class="FWSInputField" id="' . $paramHash{uniqueId} . '_day" name="' . $paramHash{uniqueId} . '_day" onchange="' . $bdayOnchange . '">';
971 $fieldHTML .= '<option>- Day -</option>';
972 for ( my $count = 1; $count <= 31; $count++ ) {
973 my $lead = '0';
974 if ( $count > 9 ) { $lead = '' }
975 $fieldHTML .= '<option value="' . $lead . $count . '">' . $count . '</option>';
976 }
977 $fieldHTML .= '</select>';
978  
979 #
980 # year
981 #
982 $fieldHTML .= '<select class="FWSInputField" id="' . $paramHash{uniqueId} . '_year" name="' . $paramHash{uniqueId} . '_year" onchange="' . $bdayOnchange . '">';
983 $fieldHTML .= '<option>- Year -</option>';
984 my $year = $self->formatDate( format => 'year' );
985 for ( my $count = $year-4; $count > $year-110; $count-- ) { $fieldHTML .= '<option value="' . $count . '">' . $count . '</option>' }
986 $fieldHTML .= '</select>';
987 }
988  
989 #
990 # textArea
991 #
992 if ( $paramHash{fieldType} eq "textArea" ) {
993 $fieldHTML .= "<textarea rows=\"8\" cols=\"70\" name=\"" . $paramHash{fieldName} . "\"" . $styleHTML . " class=\"" . $paramHash{class} . "\"";
994 }
995  
996  
997 #
998 # all but checkboxes and radio buttons
999 #
1000 if ( $paramHash{fieldType} =~ /^(dateTime|color|currency|number|text|password|textArea|dropDown|date)$/ ) {
1001 #
1002 # set the Id
1003 #
1004 $fieldHTML .= " id=\"".$paramHash{uniqueId}."\"";
1005 if ( $paramHash{readOnly} ) { $fieldHTML .= " disabled=\"disabled\"" }
1006 }
1007  
1008  
1009  
1010 #
1011 # if its a date, flip it around also update the ajax because it wont't do it on the save
1012 #
1013 if ( $paramHash{fieldType} =~ /^(date|color|dateTime)$/ ) {
1014 $fieldHTML .= " onkeyup=\"".$copyToHidden."\"";
1015 }
1016  
1017 if ( $paramHash{updateType} && $paramHash{fieldType} eq 'password') {
1018 $fieldHTML .= ' onkeyup="';
1019 if ( $paramHash{strongPassword} ) {
1020 $fieldHTML .= 'if (document.getElementById(\'' . $paramHash{uniqueId} . '\').value.search(/(?=^.{7,}$)(?=.*\\d)(?=.*[A-Z])(?=.*[a-z]).*$/) != -1) {';
1021 $fieldHTML .= "\$('#" . $paramHash{uniqueId} . "_passwordWeak').hide();";
1022 }
1023 $fieldHTML .= "\$('#" . $paramHash{uniqueId} . "_passwordStrong').show();";
1024 if ( $paramHash{strongPassword} ) {
1025 $fieldHTML .= " } else {\$('#" . $paramHash{uniqueId} . "_passwordWeak').show();\$('#" . $paramHash{uniqueId} . "_passwordStrong').hide();}";
1026 }
1027 $fieldHTML .= '"';
1028 }
1029  
1030 #
1031 # run all these if on fields, even if ajax is not on
1032 #
1033 if ( ( $paramHash{fieldType} =~ /^(dateTime|color|currency|number|text|password|textArea|date)$/ ) ) {
1034 $fieldHTML .= " onfocus=\"" . $copyToHidden . $paramHash{onFocus} ."\"";
1035 }
1036
1037 #
1038 # key down & context right clicking ajax image update
1039 #
1040 if ( $paramHash{updateType} && ( $paramHash{fieldType} =~ /^(color|dateTime|currency|number|text|password|date|textArea)$/ ) ) {
1041  
1042 #
1043 # choose a different icon
1044 #
1045 my $saveIcon = $self->{fileFWSPath} . "/save.gif";
1046 if ( $paramHash{saveIcon} ) { $saveIcon = $self->{fileFWSPath} . '/icons/' . $paramHash{saveIcon} }
1047  
1048 $fieldHTML .= " onkeydown=\"document.getElementById('" . $paramHash{uniqueId} . "_img').src='" . $saveIcon . "';";
1049  
1050 if ( $paramHash{updateType} && $paramHash{fieldType} eq 'textArea' ) {
1051 $fieldHTML .= "\$('#" . $paramHash{uniqueId} . "_status').css('visibility', 'visible');";
1052 }
1053 $fieldHTML .= $paramHash{onKeyDown};
1054 $fieldHTML .= "\" ";
1055 }
1056  
1057  
1058 #
1059 # set the onchange/onblur for the diffrent types
1060 #
1061  
1062 #
1063 # text/password
1064 #
1065 if ( $paramHash{fieldType} =~ /^(color|currency|dateTime|number|text|date)$/ ) {
1066 $fieldHTML .= " onblur=\"" . $paramHash{onChange} . $AJAXSave . "\"";
1067 }
1068  
1069 #
1070 # dropDown
1071 #
1072 if ( $paramHash{fieldType} =~ /^(dropDown|date|color|dateTime)$/ ) {
1073 $fieldHTML .= " onchange=\"" . $paramHash{onChange} . $AJAXSave . "\"";
1074 }
1075  
1076 #
1077 # if we are a radio button list, all other stuff is out the window, and this is the only thing that happens
1078 #
1079 if ( $paramHash{fieldType} eq 'radio' ) {
1080 #
1081 # clean these up in case peole did some formatting in the box
1082 #
1083 $paramHash{fieldOptions} =~ s/\n//sg;
1084 my @optionSplit = split( /\|/, $paramHash{fieldOptions} );
1085 my $matchFound = 0;
1086 $fieldHTML .= "<div class=\"FWSRadioButtonGroup\">";
1087 while (@optionSplit) {
1088 my $optionValue = shift @optionSplit;
1089 my $optionName = shift @optionSplit;
1090 $fieldHTML .= "<input type=\"radio\" name=\"" . $paramHash{fieldName} . "\"" . $styleHTML . " class=\"" . $paramHash{class} . "\"";
1091 $fieldHTML .= " onclick=\"" . $paramHash{onChange};
1092 $fieldHTML .= "\$('#" . $paramHash{uniqueId} . "_ajax').val('" . $optionValue . "');";
1093 $fieldHTML .= $AJAXSave;
1094 $fieldHTML .= '"';
1095 if ( $paramHash{readOnly} ) { $fieldHTML .= " disabled=\"disabled\"" }
1096 if ( $optionValue eq $paramHash{fieldValue} || ( $#optionSplit < 1 && !$matchFound ) ) {
1097 $matchFound = 1;
1098 $fieldHTML .= " checked=\"checked\"";
1099 }
1100 $fieldHTML .= "/> ";
1101 $fieldHTML .= "<span class=\"FWSRadioButtonTitle\">" . $optionName . " &nbsp; </span>";
1102 }
1103 $fieldHTML .= "</div>";
1104 }
1105 #
1106 #
1107 # if we are a dropDown, put the options in and close the select
1108 #
1109 if ( $paramHash{fieldType} eq 'dropDown' ) {
1110 $fieldHTML .= ">";
1111 #
1112 # clean these up in case peole did some formatting in the box
1113 #
1114 $paramHash{fieldOptions} =~ s/\n//sg;
1115 my @optionSplit = split( /\|/, $paramHash{fieldOptions} );
1116 while (@optionSplit) {
1117 my $optionValue = shift( @optionSplit );
1118 my $optionName = shift( @optionSplit );
1119 $fieldHTML .= "<option value=\"" . $optionValue . "\"";
1120 if ( $optionValue eq $paramHash{fieldValue} ) { $fieldHTML .= " selected=\"selected\"" }
1121 $fieldHTML .= ">" . $optionName . "</option>";
1122 }
1123 $fieldHTML .= "</select>";
1124 }
1125  
1126 if ( !$paramHash{fieldType} ) {
1127 $fieldHTML .= "<div class=\"FWSNoFieldType\"" . $styleHTML . ">" . $paramHash{fieldValue} . "</div>";
1128 }
1129  
1130 #
1131 # html
1132 #
1133 if ( $paramHash{fieldType} eq 'html' ) {
1134 $self->{tinyMCEEnable} = 1;
1135 }
1136  
1137 #
1138 # textArea
1139 #
1140 if ( $paramHash{fieldType} eq 'textArea' ) {
1141 $fieldHTML .= ">" . $paramHash{fieldValue} . "</textarea>";
1142 }
1143  
1144 #
1145 # if we are not an dropDown or textarea, just close the input box
1146 #
1147 if ( $paramHash{fieldType} =~ /^(color|currency|number|dateTime|text|password|date)$/ ) {
1148 $fieldHTML .= "/>";
1149 }
1150  
1151 #
1152 # add autocomplete code
1153 #
1154 if ( $paramHash{autocompleteSource} ) {
1155 $fieldHTML .= '<script>$("#' . $paramHash{uniqueId} . '" ).autocomplete({';
1156 $fieldHTML .= 'source: ' . $paramHash{autocompleteSource} . ',';
1157 $fieldHTML .= 'search: function(event, ui) {$("#' . $paramHash{uniqueId} . '_img").attr("src","' . $self->loadingImage() . '");' . $paramHash{autocompleteSearch} . '},';
1158 $fieldHTML .= 'open: function(event, ui) {$("#' . $paramHash{uniqueId} . '_img").attr("src","' . $self->{fileWebPath} . '/fws/icons/blank_16.png");' . $paramHash{autocompleteOpen} . '},';
1159 $fieldHTML .= 'select: function(event, ui) {' . $paramHash{autocompleteSelect} . '}';
1160 $fieldHTML .= '})';
1161  
1162 if ( $paramHash{autocompletePostHTML} ) {
1163 $fieldHTML .= '.data("autocomplete")._renderItem = function(ul, item) { return $("<li></li>")';
1164 $fieldHTML .= '.data("item.autocomplete", item).append("<a>" + item.value + \' ' . $paramHash{autocompletePostHTML} . '</a>\').appendTo(ul); }';
1165 }
1166 $fieldHTML .= ';</script>';
1167 }
1168  
1169  
1170 if ( $paramHash{updateType} && $paramHash{fieldType} eq "password" ) {
1171 if ( $paramHash{strongPassword} ) {
1172 $fieldHTML .= "<div id=\"" . $paramHash{uniqueId} . "_passwordWeak\" style=\"color:#FF0000;display:none;\">";
1173 $fieldHTML .= "Passwords must be at least 6 characters and contain a number, an upper case character, a lower case character.";
1174 $fieldHTML .= "</div>";
1175 }
1176 $fieldHTML .= "<div id=\"" . $paramHash{uniqueId} . "_passwordStrong\" style=\"color:#FF0000;display:none;\">";
1177 $fieldHTML .= "<img alt=\"save\" src=\"" . $self->{fileFWSPath} . "/saved.gif\" style=\"border:0pt none;\" id=\"" . $paramHash{uniqueId} . "_img\" onclick=\"" . $AJAXSave . "\"/>";
1178 $fieldHTML .= " Click the disk icon to commit your change";
1179 $fieldHTML .= "</div>";
1180 }
1181  
1182 #
1183 # stick the image in for saving if we are an updating field
1184 #
1185 if ( ( $paramHash{updateType} && ( $paramHash{fieldType} =~ /^(color|currency|dateTime|number|text|password|dropDown|date|radio)$/ ) ) || $paramHash{autocompleteSource} ) {
1186 $fieldHTML .= "<img alt=\"save\" src=\"" . $self->{fileFWSPath} . "/saved.gif\" style=\"border:0pt none;\" id=\"" . $paramHash{uniqueId} . "_img\"";
1187 if ( $paramHash{noAutoSave} ) { $fieldHTML .= " onclick=\"" . $AJAXSave . "\"" }
1188 $fieldHTML .= "/>";
1189 }
1190  
1191 #
1192 # if we are a text area, lets place lang id if needed
1193 #
1194 if ( $paramHash{fieldType} =~ /^(text|textArea)$/ ) {
1195 my $langId = $paramHash{fieldName};
1196 if ( $langId =~ /_(\w\w)$/ && $langId !~ /_id/i ) { $fieldHTML .= "[" . $1 . "]" }
1197 }
1198  
1199 #
1200 # if there is a title, wrap it with the GNF Field table!
1201 #
1202 if ( $paramHash{title} ) {
1203  
1204 my $FWSFieldTitle;
1205 my $FWSFieldValueWrapper;
1206 my $FWSFieldContainer;
1207 my $FWSFieldValue;
1208 if ( $paramHash{inlineCSS} ) {
1209 $FWSFieldTitle = " style=\"float:left;text-align:right;;color:#000000;width:25%;\"";
1210 $FWSFieldValueWrapper = " style=\"float:left;width:70%;\"";
1211 $FWSFieldContainer = " style=\"width:95%\"";
1212 }
1213  
1214 my $html = "<div class=\"FWSFieldContainer\">";
1215 $html .= "<div ".$FWSFieldTitle."class=\"FWSFieldTitle\">";
1216 if ( $paramHash{updateType} && $paramHash{fieldType} eq "textArea") { $html .= "<br/>" }
1217 $html .= $paramHash{title} . "</div>";
1218  
1219 #
1220 # add precursor
1221 #
1222 $html .= "<div class=\"FWSFieldPreCursor\" style=\"width:10px;text-align:right;float:left;\">";
1223 if ( $paramHash{fieldType} eq 'currency' ) { $html .= "\$" }
1224 else { $html .= "&nbsp;"}
1225 $html .= "</div>";
1226  
1227  
1228  
1229 $html .= "<div " . $FWSFieldValueWrapper . "class=\"FWSFieldValueWrapper\">";
1230 $html .= "<div " . $FWSFieldValue . "class=\"FWSFieldValue\">" . $fieldHTML . $paramHash{afterFieldHTML} . "</div>";
1231  
1232 if ( ( $paramHash{fieldType} =~ /^text$/ || $paramHash{fieldType} =~ /^textArea$/) && !$paramHash{unilingual} && $paramHash{fieldName} ne 'name' ) {
1233 my @langArray = $self->languageArray();
1234  
1235 #
1236 # eat the default
1237 #
1238 shift @langArray;
1239 while (@langArray) {
1240 my $langId = shift( @langArray );
1241 my %langHash = %origHash;
1242 $langHash{updateType} = 'AJAXExt';
1243 $langHash{uniqueId} = $langHash{fieldName} . '_' . $langHash{guid} . '_' . $langId;
1244 delete $langHash{title};
1245 $langHash{fieldName} = $langHash{fieldName}."_".$langId;
1246 $langHash{fieldValue} = $langHash{$langHash{fieldName}};
1247 $html .= $self->adminField(%langHash);
1248 }
1249 }
1250  
1251 if ( $paramHash{note} ) { $html .= "<div class=\"FWSFieldValueNote help-block\">" . $paramHash{note} . "</div>" }
1252 $html .= "</div>";
1253  
1254 $html .= "<div style=\"clear:both;\"></div>";
1255 $html .= "</div>";
1256 return $html;
1257 }
1258  
1259 return $fieldHTML;
1260 }
1261
1262  
1263 =head2 systemInfo
1264  
1265 Return the system info page accessed by clicking "System" from the admin menu.
1266  
1267 =cut
1268  
1269 sub systemInfo {
1270 my ( $self ) = @_;
1271 my $coreVersion = '-';
1272 my $adminInstalled = 0;
1273 my $systemInfo;
1274 my $errorReturn;
1275  
1276 #
1277 # if we are looking at systemInfo lets make sure we have a fws guid
1278 # this will make a new one if its not there for an install process
1279 #
1280 $self->fwsGUID();
1281  
1282 #
1283 # run directory checks
1284 #
1285 $errorReturn = "";
1286 $systemInfo .= "<b>File Directory Check:</b><br/>";
1287 $systemInfo .= "<ul>";
1288 $errorReturn .= $self->_systemInfoCheckDir( $self->{filePath} );
1289 $errorReturn .= $self->_systemInfoCheckDir( $self->{fileSecurePath} );
1290
1291 #
1292 # show this, if the rest works
1293 #
1294 if ( !$errorReturn ) { $errorReturn .= $self->_systemInfoCheckDir( $self->{filePath} . "/fws") }
1295 if ( !$errorReturn ) { $errorReturn .= $self->_systemInfoCheckDir( $self->{filePath} . "/fws/jquery") }
1296 if ( !$errorReturn ) {
1297 $errorReturn = "<li>All directories are present with suitable permissions.</li>";
1298 $adminInstalled = 1;
1299 }
1300  
1301 $systemInfo .= $errorReturn . "</ul>";
1302
1303 #
1304 # run Module Checks
1305 #
1306 $errorReturn = '';
1307 $systemInfo .= '<b>Perl Module Check:</b><br/>';
1308 $errorReturn .= $self->_checkIfModuleInstalled( 'Captcha::reCAPTCHA' );
1309 $errorReturn .= $self->_checkIfModuleInstalled( 'MIME::Base64' );
1310 $errorReturn .= $self->_checkIfModuleInstalled( 'CGI::Carp' );
1311 $errorReturn .= $self->_checkIfModuleInstalled( 'File::Copy' );
1312 $errorReturn .= $self->_checkIfModuleInstalled( 'File::Find' );
1313 $errorReturn .= $self->_checkIfModuleInstalled( 'Time::Local' );
1314 $errorReturn .= $self->_checkIfModuleInstalled( 'File::Path' );
1315 $errorReturn .= $self->_checkIfModuleInstalled( 'Google::SAML::Response' );
1316 $errorReturn .= $self->_checkIfModuleInstalled( 'LWP::UserAgent' );
1317 $errorReturn .= $self->_checkIfModuleInstalled( 'Crypt::SSLeay' );
1318 $errorReturn .= $self->_checkIfModuleInstalled( 'Crypt::Blowfish' );
1319 $errorReturn .= $self->_checkIfModuleInstalled( 'GD' );
1320 if ( !$errorReturn ) { $systemInfo .= '<ul><li>All required Perl Modules are present.</li></ul>' }
1321 else { $systemInfo .= $errorReturn . '<br/>' }
1322
1323 #
1324 # run go file checks
1325 #
1326 $errorReturn = '';
1327 $systemInfo .= '<b>Script compatibility Check:</b><br/>';
1328 $errorReturn .= $self->_checkScript();
1329 if ( !$errorReturn ) { $systemInfo .= '<ul><li>All script compatability checks passed.</li></ul>' }
1330 else { $systemInfo .= $errorReturn }
1331  
1332  
1333 #
1334 # Database Checks
1335 #
1336 $systemInfo .= '<b>Database Table And Index Check:</b><br/>';
1337 $errorReturn = $self->updateDatabase();
1338 if ( !$errorReturn ) { $systemInfo .= '<ul><li>All tables and indexes are correct.</li></ul>' }
1339 else {$systemInfo .= $errorReturn . '<br/>' }
1340  
1341 if ( $adminInstalled ) {
1342 $systemInfo .= "<input style=\"width:300px;\" type=\"button\" onclick=\"location.href='" . $self->{scriptName} . "?s=site';\" value=\"View Site\"/>";
1343 }
1344
1345 return $systemInfo;
1346 }
1347  
1348  
1349 =head2 aceTextArea
1350  
1351 Create an ace editor UI componate.
1352  
1353 =cut
1354  
1355 sub aceTextArea {
1356 my ( $self, %paramHash ) = @_;
1357  
1358 my $statusContainer = 'scriptChangedStatus';
1359  
1360 if ( $paramHash{statusContainer} ) { $statusContainer = $paramHash{statusContainer} }
1361
1362 #
1363 # load the JS for for ace... but only ONCE!
1364 #
1365 if ( !$self->{FWSAceJSLoaded} ) {
1366 $self->addToFoot(
1367 "<script src=\"" . $self->{fileFWSPath}."/ace-1.1.01/ace.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n" .
1368 "<script src=\"" . $self->{fileFWSPath}."/ace-1.1.01/theme-" . $self->{aceTheme} . ".js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n" .
1369 "<script src=\"" . $self->{fileFWSPath}."/ace-1.1.01/mode-javascript.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n" .
1370 "<script src=\"" . $self->{fileFWSPath}."/ace-1.1.01/mode-html.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n" .
1371 "<script src=\"" . $self->{fileFWSPath}."/ace-1.1.01/mode-perl.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n" .
1372 "<script src=\"" . $self->{fileFWSPath}."/ace-1.1.01/mode-css.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n"
1373 );
1374 $self->{FWSAceJSLoaded}++;
1375 }
1376  
1377  
1378 #
1379 # set the modes if we have them
1380 #
1381 my $modeScript;
1382 if ( $paramHash{mode} eq 'html' ) {
1383 $modeScript = "var HTMLScriptMode = require(\"ace/mode/html\").Mode;" . $paramHash{name} . ".getSession().setMode(new HTMLScriptMode());";
1384 }
1385 if ( $paramHash{mode} eq 'javascript' ) {
1386 $modeScript = "var JSScriptMode = require(\"ace/mode/javascript\").Mode;" . $paramHash{name} .".getSession().setMode(new JSScriptMode());";
1387 }
1388 if ( $paramHash{mode} eq 'perl' ) {
1389 $modeScript = "var HTMLScriptMode = require(\"ace/mode/perl\").Mode;" . $paramHash{name} . ".getSession().setMode(new HTMLScriptMode());";
1390 }
1391 if ( $paramHash{mode} eq 'css' ) {
1392 $modeScript = "var CSSScriptMode = require(\"ace/mode/css\").Mode;" . $paramHash{name} . ".getSession().setMode(new CSSScriptMode());";
1393 }
1394  
1395 $self->addToFoot( "<script type=\"text/javascript\">" .
1396 "\$(document).ready(function() {" .
1397 "window." . $paramHash{name} . " = ace.edit(\"" . $paramHash{name} . "\");" .
1398 $paramHash{name} . ".setTheme(\"ace/theme/" . $self->{aceTheme} . "\");" .
1399 $paramHash{name} . ".getSession().setUseWrapMode(true);" .
1400 $paramHash{name} . ".setShowPrintMargin(false);" . $modeScript .
1401 $paramHash{name} . ".getSession().on('change', function () {document.getElementById('" . $statusContainer . "').innerHTML='[Not Saved]';});" .
1402 "});" .
1403 "</script>\n");
1404  
1405 #
1406 # clean up thing that need to be escaped for ace
1407 #
1408 $paramHash{value} =~ s/&/&amp;/sg;
1409 $paramHash{value} =~ s/\</&lt;/sg;
1410  
1411 #
1412 # create the line that will actually be rendered to the screen
1413 #
1414 return "<pre style=\"position: absolute; padding: 0; right: 0; bottom: 0; left: 0;display:none;\" id=\"" . $paramHash{name} . "\" class=\"FWSScriptEditContainer ui-widget ui-state-default ui-corner-bottom\">" . $paramHash{value} . "</pre>";
1415 }
1416  
1417  
1418 =head2 onOffLight
1419  
1420 Return an on off lightbulb.
1421  
1422 =cut
1423  
1424 sub onOffLight {
1425 my ( $self, $status, $guid, $style ) = @_;
1426 return $self->activeToggleIcon( guid => $guid, style => $style, active => $status );
1427 }
1428  
1429  
1430 =head2 editBox
1431  
1432 Return a edit box for the passed element hash;
1433  
1434 =cut
1435  
1436 sub editBox {
1437 my ( $self, %editHash ) = @_;
1438  
1439 my $editHTML;
1440 #my $ajaxID = '#editModeAJAX_' . $self->formValue( 'FWS_elementId' );
1441 my $ajaxID = '#editModeAJAX_' . $editHash{guid};
1442  
1443 #
1444 # default always show to off if its not passed
1445 #
1446 $editHash{alwaysShow} ||= 0;
1447  
1448 #
1449 # default color
1450 #
1451 $editHash{editBoxColor} ||= '#008000;';
1452  
1453 #
1454 # Define things to blank that might not be passed that we will
1455 # use
1456 #
1457 $editHash{siteGUID} ||= '';
1458 $editHash{name} ||= '';
1459 $editHash{type} ||= '';
1460  
1461 #
1462 # if we are in edit mode, make buttons and container
1463 #
1464 if ( ( $self->formValue( 'editMode' ) || $editHash{alwaysShow} ) ) {
1465  
1466 if ( $self->{siteGUID} eq $editHash{siteGUID} || !$editHash{siteGUID} || $editHash{alwaysShow} ) {
1467
1468 #
1469 # Edit Bar Open Div Container
1470 #
1471 if ( !$editHash{editBoxJustButtons} ) {
1472 my $bgColor = $self->_getHighlightColor( $editHash{editBoxColor} );
1473 my $divStyle = "color:" . $editHash{editBoxColor} . ";background-color:".$bgColor.";border:dotted 1px " . $editHash{editBoxColor} . ";border-bottom:dotted 1px " . $editHash{editBoxColor} . ";text-align:right;";
1474
1475 $editHTML .= "<div style=\"" . $editHash{AJAXDivStyle} . "\" id=\"editModeAJAX_" . $editHash{guid} . "\">";
1476 $editHTML .= "<div style=\"" . $divStyle . "\" class=\"FWSEditBoxControls\">";
1477 $editHTML .= $editHash{name} . " ";
1478 }
1479 #
1480 # check to see if this could have children
1481 #
1482 my $showOrderButton = 0;
1483 my %elementHash = $self->_fullElementHash( typeAlso => 1 );
1484 for my $type ( keys %elementHash ) {
1485 if ( defined $elementHash{$type}{parent} ) {
1486 if ( defined $editHash{type} ) {
1487 if ( $elementHash{$type}{parent} eq $editHash{type} ) { $showOrderButton = 1 }
1488 }
1489 if ( defined $elementHash{$editHash{type}}{guid} ) {
1490 if ( $elementHash{$type}{parent} eq $elementHash{$editHash{type}}{guid} ) { $showOrderButton = 1 }
1491 }
1492 }
1493 }
1494
1495 my $layoutFlag;
1496 my $pageFlag;
1497
1498 #
1499 # if this is a column header edit box it will not have a type, which means we have to pass layout
1500 #
1501 if ( !$editHash{type} ) { $layoutFlag = "&layout=" . $editHash{layout} }
1502
1503 if ( $editHash{pageOnly} ) {
1504 $showOrderButton = 1;
1505 $pageFlag = '&pageOnly=1';
1506 $layoutFlag = '&layout=' . $editHash{layout};
1507 }
1508
1509 if ( ( $showOrderButton || $editHash{orderTool} ) && !$editHash{disableOrderTool} ) {
1510 $editHTML .= $self->FWSIcon(
1511 icon => "add_reorder_16.png",
1512 onClick => $self->dialogWindow(queryString=>"p=fws_dataOrdering&guid=" . $editHash{guid} . $pageFlag . $layoutFlag),
1513 alt => "Add And Ordering",
1514 width => "16");
1515 }
1516
1517 #
1518 # Check to see if we should put the delete trash can icon
1519 #
1520 if ( ( $editHash{deleteTool} || ( $self->{siteGUID} eq $editHash{guid_xref_site_guid} ) || $editHash{forceDelete} ) && !$editHash{disableDeleteTool} ) {
1521
1522 #
1523 # set up som vars for the post, we want to do this differntly if we are talking about
1524 # a base element, or a sub element
1525 #
1526 #my $baseClear = "\$('#delete_" . $editHash{guid} . "').parent().parent().parent().parent().parent().hide();";
1527
1528 #
1529 # If the parent isn't a page, that means we are talking about a sub element of an element.
1530 # we need to make sure the ajaxID is the parent of this element and then refresh the element in place.
1531 #
1532 # if it is a sub elemenet of an element, we also need to disable the "display none" it dosn't look goofy
1533 #
1534 #if ( $self->formValue( "FWS_pageId" ) eq $editHash{parent} && !$self->formValue( "FWS_editModeUpdate" ) ) {
1535 # $ajaxID = '<div></div>';
1536 #}
1537 #else { $baseClear = "" }
1538
1539 $editHTML .= $self->FWSIcon(
1540 icon => "delete_16.png",
1541 onClick => "\$('" . $ajaxID . "').FWSDeleteElement({pageGUID: '" . $self->formValue( 'FWS_elementId' ) . "',parentGUID: '" . $editHash{parent} . "', guid: '" . $editHash{guid} . "'});",
1542 alt => "Delete",
1543 width => "16",
1544 id => "delete_" . $editHash{guid},
1545 );
1546 }
1547
1548 #
1549 # add and order Tool Button
1550 #
1551 if ( !$editHash{disableEditTool} && $editHash{type} ne 'page') {
1552 $editHTML .= $self->FWSIcon(
1553 icon => "properties_16.png",
1554 onClick => $self->dialogWindow( queryString => "p=fws_dataEdit&guid=" . $editHash{guid} . "&parentId=" . $editHash{parent} ),
1555 alt => "Edit",
1556 width => "16",
1557 );
1558 }
1559
1560 #
1561 # ON/OFF cotnrol
1562 #
1563 if ( !$editHash{disableActiveTool} && $editHash{guid} ne $self->homeGUID() ) { $editHTML .= $self->onOffLight( $editHash{active}, $editHash{guid} ) }
1564
1565 #
1566 # close the edit bar container
1567 #
1568 if ( !$editHash{editBoxJustButtons} ) { $editHTML .= '</div>' }
1569
1570 $editHTML .= $editHash{editBoxContent};
1571 $editHTML .= $editHash{editBox};
1572
1573 #
1574 # close the delete ajax container
1575 #
1576 if ( !$editHash{editBoxJustButtons} ) { $editHTML .= '</div>' }
1577 }
1578 }
1579  
1580 #
1581 # edit mode is not on, just show the content and call this good
1582 #
1583 else { $editHTML .= $editHash{editBoxContent} . $editHash{editBox} }
1584 return $editHTML;
1585 }
1586
1587
1588 =head2 FWSMenu
1589  
1590 Return the FWS top menu bar.
1591  
1592 =cut
1593  
1594 sub FWSMenu {
1595 my ( $self, %paramHash ) = @_;
1596  
1597 #
1598 # because we have a menu, it might need tiny mce
1599 #
1600 $self->{tinyMCEEnable} = 1;
1601
1602 my $linkSpacer = " &nbsp;&middot;&nbsp; ";
1603 my $FWSMenu;
1604
1605  
1606 #
1607 # create a correct label for fws/devel link to know what we have access too
1608 #
1609 if ( $self->userValue( 'isAdmin' ) || $self->userValue( 'showDeveloper' ) ) {
1610 $FWSMenu .= $self->popupWindow( queryString => "p=fws_systemInfo", linkHTML => "System" );
1611 $FWSMenu .= $linkSpacer;
1612 }
1613  
1614 #
1615 # get the FWSMenu taged elements and add them to the list
1616 #
1617 my @elementArray = $self->elementArray( tags => 'FWSMenu' );
1618 @elementArray = $self->sortDataByNumber( 'ord', @elementArray );
1619 for my $i (0 .. $#elementArray) {
1620  
1621 #
1622 # blank out the adminGroup if we have access so we can pass by the security check
1623 #
1624 map { if ( $self->userValue( $_ ) eq 1 ) { $elementArray[$i]{adminGroup} = '' } } split( /,/, $elementArray[$i]{adminGroup} );
1625  
1626 #
1627 # if we have access or we are super user show it
1628 #
1629 if ( !$elementArray[$i]{adminGroup} || $self->userValue( 'isAdmin' ) ) {
1630
1631 #
1632 # convert to our friendly name format
1633 #
1634 ( my $fwsLink = $elementArray[$i]{type} ) =~ s/^FWS/fws_/sg;
1635
1636 #
1637 # if this is not a friendly type version menu item then use the guid
1638 #
1639 $fwsLink ||= 'fws_' . $elementArray[$i]{guid};
1640  
1641 my $queryString = "FWS_pageId=" . $paramHash{pageId} . "&p=" . $fwsLink . "&FWS_showElementOnly=";
1642 if ( $elementArray[$i]{rootElement} ) { $FWSMenu .= $self->popupWindow( queryString => $queryString . "0", linkHTML => $elementArray[$i]{title} ) }
1643 else { $FWSMenu .= $self->dialogWindow( queryString => $queryString . "1", linkHTML => $elementArray[$i]{title} ) }
1644 $FWSMenu .= $linkSpacer;
1645 }
1646 }
1647  
1648 if ( $self->formValue( "p" ) =~ /^fws_/ ) {
1649 $FWSMenu .= $self->_selfWindow( "", "View Site" );
1650 $FWSMenu .= $linkSpacer;
1651 }
1652
1653 #
1654 # ALWAYS ON
1655 #
1656 if ( $self->userValue( 'isAdmin' ) || $self->userValue( 'showDesign' ) || $self->userValue( 'showContent' ) || $self->userValue( 'showDeveloper' ) ) {
1657 $FWSMenu .= $self->_editModeLink( '', $linkSpacer );
1658 }
1659  
1660 $FWSMenu .= $self->_logOutLink();
1661
1662 if ( $self->userValue( 'isAdmin' ) || $self->userValue( 'showDesign' ) || $self->userValue( 'showContent' ) || $self->userValue( 'showDeveloper' ) ) {
1663  
1664 #
1665 # just in case we havn't installed FWS core yet, lets make sure the image is there before we
1666 # try to display it.
1667 #
1668 if ( -e $self->{filePath} . '/fws/icons/add_reorder_16.png' ) {
1669 $FWSMenu .= $linkSpacer;
1670 $FWSMenu .= $self->FWSIcon(
1671 icon => 'add_reorder_16.png',
1672 onClick => $self->dialogWindow( queryString => 'p=fws_dataOrdering&guid=' . $paramHash{pageId} . '&pageOnly=1' ),
1673 alt => 'Add And Ordering',
1674 width => '16',
1675 );
1676 }
1677 }
1678  
1679 $FWSMenu .= $linkSpacer;
1680  
1681 return $FWSMenu;
1682 }
1683  
1684  
1685 =head2 panel
1686  
1687 FWS panel HTML: Pass title, content and panelStyle keys.
1688  
1689 =cut
1690  
1691 sub panel {
1692 my ( $self, %paramHash ) = @_;
1693
1694 my $panel;
1695  
1696 if ( $paramHash{inline} ) {
1697 $panel .= "<div style=\"width:95%;font-size:12px;margin-top:10px;padding-bottom:10px;margin-bottom:10px;border: 1px solid #d3d3d3; padding:10px;background: #ffffff; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; font-weight: normal; color: #555555;" . $paramHash{panelStyle} . "\" class=\"FWSPanel ui-widget ui-widget-content ui-corner-all\">";
1698 $panel .= "<div style=\"padding:5px 15px 15px 15px;font-weight:800;font-size:14px;color:#2B6FB6;\" class=\"FWSPanelTitle\">" . $paramHash{title} . "</div>";
1699 $panel .= "<div steyl=\" padding:5px 15px 15px 15px;font-size:12px;\" class=\"FWSPanelContent\">" . $paramHash{content} . "</div>";
1700 $panel .= "</div>";
1701 }
1702 else {
1703 $panel .= "<div ";
1704 if ( defined $paramHash{panelStyle} ) { $panel .= "style=\"" . $paramHash{panelStyle} . "\" " }
1705 $panel .= "class=\"FWSPanel ui-widget ui-widget-content ui-corner-all\">";
1706 $panel .= "<div class=\"FWSPanelTitle\">" . $paramHash{title} . "</div>";
1707 $panel .= "<div class=\"FWSPanelContent\">" . $paramHash{content} . "</div>";
1708 $panel .= "</div>";
1709 }
1710 return $panel;
1711 }
1712  
1713  
1714 =head2 displayAdminPage
1715  
1716 Run the lookup and display admin pages wrapped in security precautions.
1717  
1718 =cut
1719  
1720 sub displayAdminPage {
1721 my ( $self ) = @_;
1722  
1723 #
1724 # mimic the normal element processing controls
1725 #
1726 my $pageHTML;
1727 my $showElementOnly = 0;
1728 my $quitPageProcessing = 0;
1729 my $pageId = $self->safeSQL( $self->formValue( 'p' ) );
1730
1731 if ( $self->isAdminLoggedIn() ) {
1732 $self->jqueryEnable( 'simplemodal-1.4.4' );
1733 $self->jqueryEnable( 'ui.core-1.8.9' );
1734 $self->jqueryEnable( 'ui.widget-1.8.9' );
1735 $self->jqueryEnable( 'ui.tabs-1.8.9' );
1736 $self->jqueryEnable( 'ui.fws-1.8.9' );
1737 $self->jqueryEnable( 'fileupload-ui-4.4.1' );
1738 $self->jqueryEnable( 'fileupload-4.5.1' );
1739 $self->jqueryEnable( 'fileupload-uix-4.6' );
1740  
1741 #
1742 # see if we looking at a dynamicly created admin page
1743 #
1744 if ( $pageId =~ /^fws_/ ) {
1745 my %elementHash = $self->_fullElementHash();
1746 for my $guid ( sort { $elementHash{$a}{alphaOrd} <=> $elementHash{$b}{alphaOrd} } keys %elementHash ) {
1747  
1748 #
1749 # trim up what these actually look like to match naming
1750 #
1751 ( my $fwsElementType = $pageId ) =~ s/fws_//sg;
1752 $fwsElementType = 'FWS' . ucfirst( $fwsElementType );
1753  
1754 if ( $self->{_fullElementHashCache}->{$guid}{type} eq $fwsElementType || "fws_" . $guid eq $pageId ) {
1755
1756 my %elementHash = $self->elementHash( guid => $guid );
1757
1758 #
1759 # blank out the adminGroup if we have access so we can pass by the security check
1760 #
1761 map { if ( $self->userValue( $_ ) eq 1 ) { $elementHash{adminGroup} = '' } } split( /,/, $elementHash{adminGroup} );
1762
1763 #
1764 # if we have access or we are super user show it
1765 #
1766 if ( !$elementHash{adminGroup} || $self->userValue( 'isAdmin' ) ) {
1767
1768 my %valueHash;
1769 $valueHash{pageId} = $pageId;
1770 $valueHash{elementId} = $guid;
1771 $valueHash{elementWebPath} = $self->fileWebPath() . "/" . $elementHash{siteGUID} . "/" . $valueHash{elementId};
1772
1773 my $fws = $self;
1774
1775 ## no critic
1776 eval $elementHash{scriptDevel};
1777 ## use critic
1778 my $errorCode = $@;
1779 if ( $errorCode ) {
1780 $valueHash{html} .= "<div style=\"border:solid 1px;font-weight:bold;\">FrameWork Element Error:</div><div style=\"font-style:italic;\">".$errorCode."</div>";
1781 }
1782
1783 #
1784 # now put it back
1785 #
1786 $self = $fws;
1787
1788 #
1789 # set head and foot from cache so we can use it for our admin page
1790 #
1791 $self->{tinyMCEEnable} = 1;
1792 $self->{bootstrapEnable} = 1;
1793 $self->setPageCache();
1794
1795 #
1796 # just in case we havn't rendered yet, here we go! if we have already rendered (like we should have
1797 # than this just gets passed by
1798 #
1799 #$self->printPage( content => $valueHash{html} . $fws->{ 'pageFoot' } , head => $self->FWSHead() );
1800 # $self->printPage( content => $valueHash{html} . $fws->{ 'pageFoot' } , head => $self->{pageHead} );
1801 $self->printPage( content => $valueHash{html}, head => $self->FWSHead(), foot => $self->siteValue( 'pageFoot' ) );
1802 }
1803 }
1804 }
1805 }
1806  
1807
1808 #
1809 # this one does not run in an element, because it installs the elements!
1810 #
1811 if ( $pageId eq 'fws_systemInfo' ) {
1812
1813 my $coreElement;
1814 if ( !$self->{hideFWSCoreUpgrade} ) {
1815 $coreElement .= "<br/><input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('This could take several moments after you click ok.";
1816 $coreElement .= " Do you want to continue?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=installCore';}\" value=\"Install Full Core Element &amp;&nbsp;File Package\"/> ";
1817 $coreElement .= ' Use for new installs or if your having FWS related javascript errors.';
1818 $coreElement .= "<div class=\"FWSStatusNote\">".$self->formValue("coreStatusNote")."</div>";
1819 }
1820  
1821  
1822  
1823 my $log = "<input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('Are you sure you clear the FWS log file?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=clearFWSLog';}\" value=\"Clear FWS Log\"/> ";
1824 my $FWSLogSize = -s $self->{fileSecurePath} . '/FWS.log';
1825 $log .= 'FWS.Log ' . sprintf( "%0.1f", $FWSLogSize/1000 ). 'K size <a target="_blank" href="' . $self->{scriptName} . $self->{queryHead} . 'p=fws_log&lines=50">View</a>';
1826 $log .= "<div class=\"FWSStatusNote\">".$self->formValue("logStatusNote")."</div>";
1827  
1828  
1829 my %sessionInfo = $self->_sessionInfo();
1830 my $sess = "<input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('Are you sure you delete all sessions?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=flushSessions&months=0';}\" value=\"Delete All Sessions\"/> ";
1831 $sess .= $sessionInfo{total}." sessions total<br/>";
1832 $sess .= "<input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('Are you sure you delete sessions more than 1 month old?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=flushSessions&months=1';}\" value=\"Delete All Sessions More Than 1 Month Old\"/> ";
1833 $sess .= $sessionInfo{1}." sessions over 30 days old<br/>";
1834 $sess .= "<input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('Are you sure you delete sessions more than 3 months old?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=flushSessions&months=3';}\" value=\"Delete All Sessions More Than 3 Months Old\"/> ";
1835 $sess .= $sessionInfo{3}." sessions over 90 days old";
1836 $sess .= "<div class=\"FWSStatusNote\">".$self->formValue("sessionStatusNote")."</div>";
1837  
1838 my $backup;
1839 $backup = "Backup file name:<br/>";
1840 $backup .= "<input style=\"width:150px;\" type=\"text\" name=\"backupName\" id=\"backupName\" />";
1841 $backup .= "<input style=\"width:150px;\" type=\"button\" onclick=\"if(confirm('This could take several minutes depending on the size of your data.";
1842 $backup .= " Do you want to continue?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . " p=fws_systemInfo&excludeSiteFiles='+document.getElementById('excludeSiteFiles').checked+'&backupName='+escape(document.getElementById('backupName').value)+'&pageAction=FWSBackup';}\" value=\"Backup Now\"/> ";
1843 $backup .= ' This will make a backup of your FWS Site files,&nbsp;plugins,&nbsp;and database';
1844 $backup .= "<div class=\"FWSExcludeBackup\"><input type=\"checkbox\" name=\"excludeSiteFiles\" id=\"excludeSiteFiles\" /> Do not backup web accessible site uploaded files</div>";
1845 $backup .= "<div class=\"FWSStatusNote\">".$self->formValue("backupStatusNote")."</div>";
1846  
1847 $backup .= "Restore file name:<br/>";
1848 $backup .= "<input style=\"width:150px;\" type=\"text\" name=\"restoreName\" id=\"restoreName\" />";
1849 $backup .= "<input style=\"width:150px;\" type=\"button\" onclick=\"if(confirm('WARNING!!! This will ovewrite your database and files.";
1850 $backup .= " Do you want to continue?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&restoreName='+escape(document.getElementById('restoreName').value)+'&pageAction=FWSRestore';}\" value=\"Restore Now\"/> ";
1851 $backup .= ' Overwrite your database,&nbsp;files,&nbsp;and plugins with a backup';
1852 $backup .= "<div class=\"FWSStatusNote\">".$self->formValue("restoreStatusNote")."</div>";
1853  
1854 my $publish = "<input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('Are you sure you flush your search cache? (Depending on the size of your site this could take several minutes)')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=flushSearchCache';}\" value=\"Rebuild Search Cache\"/>";
1855 $publish .= " Replace all search cache, and update parent page references. (This will be slow on large sites)<br/>";
1856 $publish .= "<input style=\"width:300px;\" type=\"button\" onclick=\"if(confirm('Are you sure you flush your web cache?')) {location.href='" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo&pageAction=flushWebCache';}\" value=\"Flush Web Cache\"/>";
1857 $publish .= " Remove all combined js and css files, and recreate them as needed.";
1858 $publish .= "<div class=\"FWSStatusNote\">" . $self->formValue("statusNote") . "</div>";
1859  
1860 #
1861 # DB Pakckages
1862 #
1863 my $dbPackages;
1864 $dbPackages .= "<table border=\"1\" cellspacing=\"0\" style=\"margin-left:40px;width:90%;".$self->fontCSS()."\">";
1865 $dbPackages .= "<tr>";
1866 $dbPackages .= "<th>Module or Element Name</th>";
1867 $dbPackages .= "<th>Your Version</th>";
1868 $dbPackages .= "<th>Current Version</th>";
1869 $dbPackages .= "<th>&nbsp;</th>";
1870 $dbPackages .= "</tr>";
1871 $dbPackages .= $self->_packageLine( "US Zip Code Package", ( $self->_versionData( 'local', 'zipcode' ) )[0],( $self->_versionData( 'live', 'zipcode' ) )[0], "fws_installZipcode" );
1872 $dbPackages .= $self->_packageLine( "Country Package", ( $self->_versionData( 'local', 'country' ) )[0], ( $self->_versionData( 'live', 'country' ) )[0], "fws_installCountry" );
1873 $dbPackages .= "</table>";
1874  
1875  
1876 $pageHTML .= "<div style=\"width:90%;margin:auto;padding:10px;text-align:right;color:#ff0000;\">FrameWork&nbsp;Sites&nbsp;Version&nbsp; " . $self->{FWSVersion} . "</div>";
1877 $pageHTML .= $self->panel( title => "FWS Installation And Health" ,content => $self->systemInfo() . $coreElement );
1878 $pageHTML .= $self->panel( title => "Session Maintenance" ,content => $sess);
1879 $pageHTML .= $self->panel( title => "Log Files" ,content => $log);
1880 $pageHTML .= $self->panel( title => "FWS Site Backups" ,content => $backup);
1881 $pageHTML .= $self->panel( title => "Flush Cache Engines" ,content => $publish);
1882 $pageHTML .= $self->panel( title => "Core Database Packages" ,content => $dbPackages);
1883 $self->siteValue("pageHead","");
1884 $self->siteValue("pageKeywords","");
1885 $self->siteValue("pageDescription","");
1886  
1887 $self->printPage( title => "FrameWork&nbsp;Sites&nbsp;Version&nbsp; " . $self->{FWSVersion} . " System Info", content => $pageHTML, head=> $self->_minCSS() );
1888 }
1889  
1890 #
1891 # do install subroutines
1892 #
1893 if ( $pageId eq 'fws_installCountry' ) { $pageHTML .= $self->_installCountry() }
1894 if ( $pageId eq 'fws_installZipcode' ) { $pageHTML .= $self->_installZipcode() }
1895  
1896 }
1897  
1898 #
1899 # Show the admin login if we didn't meet isAdminLoggedIn
1900 #
1901 else { $self->displayAdminLogin() }
1902  
1903 return;
1904 }
1905  
1906  
1907 =head2 GNFTree
1908  
1909 Tree render componate. At some point this will be rewritten using a JQuery tree and migrate away from this server side rendering method.
1910  
1911 =cut
1912  
1913 sub GNFTree {
1914 my ( $self, %paramHash ) = @_;
1915  
1916 #
1917 # parentId is implied usually via formValue parentId, but if your passing it, lets use that one
1918 #
1919 $paramHash{parentId} ||= $self->formValue( 'parentId' );
1920  
1921 #
1922 # if this is not in a modal pass noModal
1923 #
1924 $paramHash{noModal} ||= 0;
1925  
1926 #
1927 # remove any reference to id_ - this is legacy
1928 #
1929 $paramHash{id} =~ s/^id_//sg;
1930  
1931 #
1932 # create the depth lines, if there is a line map use this way if there is a depth use the other
1933 #
1934 my $lineHTML;
1935 if ( $paramHash{lineMap} ne '' ) { $lineHTML = $self->_createLineMap( %paramHash ) }
1936  
1937 #
1938 # create the depth lines, if there is a line map use this way if there is a depth use the other
1939 #
1940 if ( $paramHash{depth} > 0 ) {
1941  
1942 # Add the lines for how deep it is
1943 #
1944 for (my $count = 0; $count < ( $paramHash{depth} -1 ); $count++ ) {
1945 $lineHTML .= "<img class=\"FWSTreeEventRowImage\" alt=\"\" src=\"" . $self->{fileFWSPath} . "/line.gif\"/>";
1946 }
1947  
1948 if ( $paramHash{expandQuery} ) {
1949 if ( $paramHash{lastInList} ) {
1950 $lineHTML .= "<img class=\"FWSTreeEventRowImage\" src=\"" . $self->{fileFWSPath} . "/plus.gif\" id=\"tree" . $paramHash{id} . "\"/>";
1951 }
1952 else {
1953 $lineHTML .= "<img class=\"FWSTreeEventRowImage\" src=\"" . $self->{fileFWSPath} . "/plusbottom.gif\" id=\"tree" . $paramHash{id} . "\"/>";
1954 }
1955 }
1956 else {
1957 $lineHTML .= "<a href=\"#\" name=\"parentAnchor" . $paramHash{categoryId} . "\"></a>";
1958 if ( $paramHash{lastInList} ) {
1959 $lineHTML .= "<img class=\"FWSTreeEventRowImage\" src=\"" . $self->{fileFWSPath} . "/join.gif\" id=\"tree" . $paramHash{id} . "\"/>";
1960 }
1961 else {
1962 $lineHTML .= "<img class=\"FWSTreeEventRowImage\" src=\"" . $self->{fileFWSPath} . "/joinbottom.gif\" id=\"tree" . $paramHash{id} . "\"/>";
1963 }
1964 }
1965 }
1966  
1967  
1968 #
1969 # create the table the line item will sit in
1970 #
1971 my $treeHTML = "<div id=\"block_" . $paramHash{id} . "\">";
1972 $treeHTML .= "<div class=\"FWSTreeEventRow " . $paramHash{class} . "\" onmouseover=\"this.className='FWSTreeEventRow " . $paramHash{class} . " FWSTreeEventRowHighlight';\" onmouseout=\"this.className='FWSTreeEventRow';\" id=\"row_" . $paramHash{id} . "\">";
1973
1974 #my $treeHTML .= "<div class=\"FWSTreeEventRow " . $paramHash{class} . "\" onmouseover=\"this.className='FWSTreeEventRowHighlight';\" onmouseout=\"this.className='FWSTreeEventRow';\" id=\"block_" . $paramHash{id} . "\">";
1975  
1976 #
1977 # add the + - thing
1978 #
1979 $treeHTML .= "<span class=\"FWSTreeLeft\"";
1980 if ( $paramHash{expandQuery} ) {
1981 $treeHTML .= " style=\"cursor:pointer;\" ";
1982 $treeHTML .= "onclick=\"GNFTreeUpdate('" . $paramHash{id} . "','" . $self->{scriptName} . "','" . $self->{queryHead} . $paramHash{expandQuery} . "',0,0," . ( $paramHash{lastInList} + 0 ) . "," . $paramHash{noModal} . ");return false;\"";
1983 }
1984 $treeHTML .= ">";
1985  
1986 #
1987 # do the line art to the left of the content title of the line
1988 #
1989 $treeHTML .= $lineHTML;
1990  
1991 #
1992 # add the icon
1993 #
1994 my $checkedOutClass;
1995 if ( $paramHash{icon} =~ /lock/i ) { $checkedOutClass = "checkedOutTip "; }
1996
1997 $treeHTML .= "<img class=\"" . $checkedOutClass . "FWSTreeEventRowImage\" alt=\"\" src=\"" . $self->{fileFWSPath} . "/" . $paramHash{icon} . "\"/>";
1998
1999 $treeHTML .= '<div class="FWSTreeLineTitle">';
2000 $treeHTML .= "&nbsp;" . $paramHash{name};
2001 $treeHTML .= "</div>";
2002  
2003 $treeHTML .= "</span>";
2004  
2005 #
2006 # if this is an add line do a add td sequence, and close table
2007 #
2008 if ( $paramHash{addField1} || $paramHash{addCustom1} ) {
2009 #
2010 # if there is a hidden field toss it in
2011 #
2012 if ( $paramHash{addHiddenField1} ) {
2013 $treeHTML .= "<input value=\"" . $paramHash{addHiddenFieldValue1} . "\" type=\"hidden\" id=\"add_" . $paramHash{addHiddenField1} . "_" . $paramHash{parentId} . "\" name=\"add_" . $paramHash{addHiddenField1} . "_" . $paramHash{parentId} . "\"/>";
2014 }
2015  
2016 #
2017 # add up to 10 fields if needed
2018 #
2019
2020 for ( my $i = 1; $i < 10; $i++ ) {
2021 if ( $paramHash{'addField' . $i} || $paramHash{'addCustom' . $i} ) {
2022 $treeHTML .= "<div class=\"FWSTreeAddField\">" . $paramHash{'addLabel' . $i} . "<br/>";
2023  
2024 #
2025 # set the default addType to text
2026 #
2027 $paramHash{'addType' . $i} ||= 'text';
2028  
2029 if ( defined $paramHash{'addCustom' . $i} ) { $treeHTML .= $paramHash{'addCustom' . $i} }
2030 else {
2031 $treeHTML .= "<input value=\"" . $self->formValue( $paramHash{'addField' . $i} ) . "\" type=\"" . $paramHash{'addType' . $i} . "\" style=\"" . $paramHash{'addFieldStyle' . $i} . "\" id=\"add_" . $paramHash{'addField' . $i} . "_" . $paramHash{parentId} . "\" name=\"" . $paramHash{'addField' . $i} . "_".$paramHash{parentId} . "\"/>";
2032 }
2033 $treeHTML .= "</div>";
2034 }
2035 }
2036
2037
2038 #
2039 # set the addPageAction field
2040 #
2041 my $addPageField = 'pageAction';
2042 if ( $paramHash{addPageField} ) { $addPageField = $paramHash{addPageField} }
2043  
2044 #
2045 # add the "go" button
2046 #
2047 $treeHTML .= "<div class=\"FWSTreeAddField\"><br/>";
2048 my $onClickGo;
2049 if ( $paramHash{addHiddenField1} ) {
2050 $onClickGo .= "&" . $paramHash{addHiddenField1} . "='+escape(document.getElementById('add_" . $paramHash{addHiddenField1} . '_' . $paramHash{parentId} . "').value)+'";
2051 }
2052 for ( my $i = 1; $i < 10; $i++ ) {
2053 if ( $paramHash{'addField' . $i} ) {
2054 $onClickGo .= "&" . $paramHash{'addField' . $i} . "='+escape(document.getElementById('add_" . $paramHash{'addField' . $i} . '_' . $paramHash{parentId} . "').value)+'";
2055 }
2056 }
2057 if ( $onClickGo ) {
2058 $treeHTML .= " " . $self->FWSIcon( icon =>"go_16.png",
2059 onClick => "this.src='" . $self->loadingImage() . "';\$('#cat" . $paramHash{parentId} . "').FWSAjax({queryString: '" . $self->{queryHead} . "&guid=" . $self->formValue("id") . "&id=" . $self->formValue("id") . "&parentId=" . $paramHash{parentId} . "&p=" . $self->formValue("p") . "&".$addPageField . "=" . $paramHash{'addPageAction'} . "&depth=" . $self->formValue("depth") . $onClickGo . "',showLoading:false});return false;",
2060 alt =>"go",
2061 width =>"16",
2062 style =>"padding-left:3px;vertical-align:middle;");
2063  
2064 }
2065 $treeHTML .= "</div>";
2066 }
2067  
2068  
2069 #
2070 # make an easy access to see if it has labels
2071 #
2072 my $hasLabel = 0;
2073 if ( $paramHash{label1} || $paramHash{label2} || $paramHash{label3} || $paramHash{label4} || $paramHash{label5} || $paramHash{label6} || $paramHash{label7} || $paramHash{label8} || $paramHash{label9} || $paramHash{label10} || $paramHash{label11} || $paramHash{label12} || $paramHash{label13} || $paramHash{label14} || $paramHash{label15} || $paramHash{label16} ) { $hasLabel = 1 }
2074  
2075 #
2076 # this isn't an "add line" finish out the standard tree
2077 #
2078 if ( $paramHash{searchOnClick} || $paramHash{actionHTML} || $hasLabel) {
2079 if ( $paramHash{searchOnClick} || $hasLabel ) {
2080 $treeHTML .= "<div class=\"FWSTreeSearch\">";
2081 $treeHTML .= $self->FWSIcon(
2082 icon => "go_16.png",
2083 onClick => $paramHash{onClick1} . $paramHash{searchOnClick},
2084 id => "sel_" . $paramHash{id} . "_" . $paramHash{parentId},
2085 alt => "go",
2086 width => "16",
2087 style => "padding-left:3px;vertical-align:middle;"
2088 );
2089 $treeHTML .= "</div>";
2090 }
2091
2092 $treeHTML .= "<div class=\"FWSTreeSearch\">";
2093 if ( $paramHash{actionHTML} ) { $treeHTML .= $paramHash{actionHTML} }
2094  
2095 if ( $hasLabel ) {
2096 $treeHTML .= "<select style=\"width:180px;\" onchange=\"";
2097  
2098 for ( my $i = 1; $i < 17; $i++ ) {
2099 if ( $paramHash{'onClick' . $i} ) {$treeHTML .= "if (this.value == $i) {document.getElementById('sel_" . $paramHash{id} . "_" . $paramHash{parentId} . "').onclick=function() {" . $paramHash{'onClick' . $i} . "return false;}}" }
2100 }
2101 $treeHTML .= "\">";
2102
2103 for ( my $i = 1; $i < 17; $i++ ) { if ( $paramHash{'label' . $i} ) {$treeHTML.="<option value=\"" . $i . "\">" . $paramHash{'label' . $i}."</option>"} }
2104 $treeHTML.= "</select>";
2105 }
2106 if ( $paramHash{searchOnClick} ) {
2107 $treeHTML .= "<input style=\"width:175px;\" type=\"text\" id=\"" . $paramHash{searchField} . "\" name=\"" . $paramHash{searchField} . "\"/>";
2108 }
2109 $treeHTML .= "</div>";
2110
2111 }
2112 else {
2113 #
2114 # we don"t have a dropdown slector, use the tool set view
2115 # Page View Tool
2116 #
2117  
2118 $treeHTML .= "<div class=\"FWSActionButton\">";
2119 if ( $paramHash{viewTool} ) {
2120 my $editURL = $self->{scriptName} . $self->{queryHead};
2121 $editURL .= "&editMode=1";
2122 $editURL .= "&p=" . $paramHash{id};
2123 $treeHTML .= "<img alt=\"Open Page\" onclick=\"location.href='" . $editURL . "';\" title=\"" . $paramHash{id} . "\" style=\"cursor:pointer;display:inline;border:0pt none;\" src=\"" . $self->{fileFWSPath} . "/icons/go_16.png\"/>";
2124 }
2125 else { $treeHTML .= "&nbsp;" };
2126 $treeHTML .= "</div>";
2127
2128 #
2129 # The Delete Tool
2130 #
2131 $treeHTML .= "<div class=\"FWSActionButton\">";
2132 if ( $paramHash{deleteTool} ) {
2133 $treeHTML .= $self->FWSIcon(
2134 icon => "delete_16.png",
2135 onClick => "if (confirm('Are you sure you want to delete this item and all of its related sub items? (Non-reversable)'" .
2136 ")){FWSAjax('" . $self->{scriptName} . "','" . $self->{queryHead} .
2137 "p=fws_dataEdit&pageAction=deleteElement&parent=" . $paramHash{parentId} .
2138 "&guid=" . $paramHash{id} . "');" .
2139 "\$('#block_" . $paramHash{id} . "').hide('slow');}return false;",
2140 alt => "Delete",
2141 width => "16",
2142 );
2143 }
2144 elsif ( $paramHash{emailDeleteTool} ) {
2145 $treeHTML .= $self->FWSIcon(
2146 icon =>"delete_16.png",
2147 onClick => "if (confirm('Are you sure you want to delete this message? (Non-reversable)'" .
2148 ")){FWSAjax('" . $self->{scriptName} . "','" . $self->{queryHead} .
2149 "&pageAction=deleteMessage" .
2150 "&guid=" . $paramHash{id} . "');" .
2151 "\$('#block_" . $paramHash{id} . "').hide('slow');}return false;",
2152 alt => "Delete",
2153 width => "16",
2154 );
2155 }
2156 else { $treeHTML .= "&nbsp;" };
2157 $treeHTML .= "</div>";
2158  
2159
2160 #
2161 # 3dit tool
2162 #
2163 $treeHTML .= "<div class=\"FWSActionButton\">";
2164 if ( $paramHash{emailEditTool} ) {
2165 $treeHTML .= $self->FWSIcon(
2166 icon => "properties_16.png",
2167 onClick => $self->dialogWindow( queryString => "p=fws_messageEdit&guid=" . $paramHash{id} ),
2168 alt => "Edit",
2169 width => "16",
2170 );
2171 }
2172 if ( $paramHash{pageTool} ) {
2173 $treeHTML .= $self->FWSIcon(
2174 icon => "properties_16.png",
2175 onClick => $self->popupWindow( queryString => "p=fws_pageEdit&FWS_pageId=" . $paramHash{guid} . "&FWS_showElementOnly=0" ),
2176 alt => "Edit",
2177 width => "16",
2178 id => "edit_".$paramHash{id},
2179 );
2180 }
2181 else {
2182 $treeHTML .= "&nbsp;"
2183 }
2184
2185 $treeHTML .= "</div>";
2186  
2187 #
2188 # on off tool
2189 #
2190 $treeHTML .= "<div class=\"FWSActionButton\">";
2191 if ( $paramHash{activeTool} ) {
2192 $treeHTML .= $self->onOffLight( $paramHash{active}, $paramHash{guid} );
2193 }
2194 else {
2195 $treeHTML .= "&nbsp;";
2196 }
2197
2198 $treeHTML .= "</div>";
2199
2200 #
2201 # template Tool
2202 #
2203 if ( $paramHash{templateTool} ) {
2204 if ( !$self->formValue( "templateList" ) ) {
2205  
2206 $self->formValue( "templateList", "0|Default Template|" );
2207  
2208 #
2209 # get the array of all the templates availalbe
2210 #
2211 my @templateArray = $self->templateArray();
2212  
2213 #
2214 # loop through them and create a pipe delimited list
2215 #
2216 for my $i (0 .. $#templateArray) {
2217 $self->formValue( "templateList", $self->formValue( "templateList" ) . $templateArray[$i]{guid} . "|" . $templateArray[$i]{title} . "|" );
2218 }
2219 }
2220  
2221 $treeHTML .= "<div style=\"float:right;\">" . $self->adminField(
2222 fieldType => 'dropDown',
2223 fieldValue => $paramHash{layout},
2224 style => 'width:200px;',
2225 fieldName => 'layout',
2226 fieldOptions => $self->formValue( 'templateList' ),
2227 updateType => 'AJAXUpdate',
2228 ajaxUpdateTable => 'guid_xref',
2229 ajaxUpdateParentId => $paramHash{parentId},
2230 ajaxUpdateGUID => $paramHash{guid}
2231 );
2232  
2233 $treeHTML .= "</div>";
2234 $treeHTML .= "<div style=\"float:right;\">";
2235 if ( !$paramHash{id} ) {
2236 $treeHTML .= "Home Page ";
2237 }
2238 $treeHTML .= "Template:";
2239 $treeHTML .= "</div>";
2240
2241 }
2242 }
2243 $treeHTML .= "<div style=\"float:right;\" class=\"FWSTreeSearch\">";
2244 $treeHTML .= $paramHash{searchLabel};
2245 $treeHTML .= '</div>';
2246  
2247  
2248 if ( $paramHash{dateRange} ) {
2249  
2250 $paramHash{fromLabel} ||= 'From: ';
2251  
2252 my $fromId = $paramHash{dateRange} . "From";
2253 my $toId = $paramHash{dateRange} . "To";
2254 $treeHTML .= "<div style=\"float:right;margin-right:10px;\" class=\"FWSDateRange\">" . $paramHash{fromLabel};
2255  
2256 #
2257 # set some smart starts and ends
2258 #
2259 my $fromDate = $self->formatDate( format => 'SQL', monthMod => -1 );
2260 my $toDate = $self->formatDate( format => 'SQL' );
2261 if ( $paramHash{dateRange} eq 'onlyLate' ) {
2262 $fromDate = '0000-00-00';
2263 }
2264 if ( $paramHash{dateRange} eq 'check' ) {
2265 $toDate = $self->formatDate( format => 'SQL', monthMod => 1 );
2266 $fromDate = $self->formatDate( format => 'SQL' );
2267 }
2268
2269 $treeHTML .= $self->adminField(
2270 fieldType => 'date',
2271 fieldValue => $fromDate,
2272 fieldName => $fromId,
2273 id => $fromId,
2274 style => 'width:70px;',
2275 );
2276  
2277 $treeHTML .= "&nbsp;To: ";
2278  
2279 $treeHTML .= $self->adminField(
2280 fieldType => 'date',
2281 fieldValue => $toDate,
2282 fieldName => $toId,
2283 id => $toId,
2284 style => 'width:70px;',
2285 );
2286 $treeHTML .= "</div>";
2287
2288 }
2289  
2290 #
2291 # close the the DIV send a clear and return the html
2292 #
2293 $treeHTML .= "</div>";
2294 $treeHTML .= "<div style=\"clear:both;\"></div>";
2295 return $treeHTML . "<div style=\"\" id=\"cat" . $paramHash{id} . "\"></div></div>";
2296 }
2297  
2298 sub _selfWindow {
2299 my ( $self, $queryString, $linkHTML, $extraJava ) = @_;
2300 return "<span style=\"cursor:pointer;\" class=\"FWSAjaxLink\" onclick=\"location.href='" . $self->{scriptName} . $self->{queryHead} . $queryString . "';" . $extraJava . "\">" . $linkHTML . "</span>";
2301 }
2302  
2303 sub _isSiteUsed {
2304 my ( $self, $fieldValue ) = @_;
2305 my ( $siteUsed ) = @{$self->runSQL( SQL => "select 1 from site where site.sid='" . $self->safeSQL( $fieldValue ) . "'" )};
2306 if ( $siteUsed ) { return 1 }
2307 return 0;
2308 }
2309  
2310 sub _isValidSID {
2311 my ( $self, $siteValid ) = @_;
2312 my $returnStatus;
2313 if ( $siteValid =~ /[^a-z]/ ) {
2314 $returnStatus .= "The Site ID must only contain lower case characters without any spaces or symbols. ";
2315 }
2316 if ( length( $siteValid ) < 4 && $siteValid ne 'fws' ) {
2317 $returnStatus .= "The Site ID must be at least 4 characters long. ";
2318 }
2319 if ( length( $siteValid ) > 8 ) {
2320 $returnStatus .= "The Site ID must be 8 characters or less. ";
2321 }
2322 if ( $self->_isSiteUsed( $siteValid ) && $siteValid && $siteValid ne 'fws' ) {
2323 $returnStatus .= "The Site ID has already been taken. ";
2324 }
2325 return $returnStatus;
2326 }
2327  
2328 sub _processAdminAction {
2329 my ( $self ) = @_;
2330  
2331 my $guid = $self->safeSQL( $self->formValue( 'guid' ) );
2332  
2333 #
2334 # To prevent recursive saves we have to update elements insdie the core
2335 #
2336 if ($self->userValue( 'isAdmin') || $self->userValue('showDeveloper')) {
2337 if ( $self->formValue( 'pageAction' ) eq 'updateScript' ) {
2338 my %valueHash;
2339 my $fws = $self;
2340 ## no critic
2341 eval $self->formValue( 'script' );
2342 ## use critic
2343 if ( $@ ) { $self->formValue( 'statusNote', '<textarea style="width:800px;height:67px;font-size:10px;">'.$@.'</textarea><br/>' ) }
2344 else {
2345 my $script = $self->safeSQL( $self->formValue( "script" ) );
2346 my $schema = $self->safeSQL( $self->formValue( "schema" ) );
2347 my $checkedOut = $self->safeSQL($self->formValue("checkout"));
2348 $self->runSQL(SQL=>"update element set schema_devel='".$schema."', script_devel='".$script."', checkedout='".$checkedOut."' where guid='" . $self->safeSQL( $self->formValue( 'guid' ) ) . "'");
2349 $self->_saveElementFile( $self->formValue( 'guid' ), $self->formValue('site_guid'), 'element', 'css', $self->formValue("css") );
2350 $self->_saveElementFile( $self->formValue( 'guid' ), $self->formValue('site_guid'), 'element', 'js', $self->formValue("javaScript") );
2351 $self->formValue( 'statusNote', '' );
2352 }
2353 }
2354
2355 if ( $self->formValue( 'pageAction' ) eq "FWSRestore") {
2356 $self->restoreFWS( id => $self->formValue( 'restoreName' ) );
2357 $self->formValue( 'restoreStatusNote', 'Restore completed' );
2358 }
2359  
2360
2361 }
2362 if ($self->userValue( 'isAdmin') || $self->userValue('showDeveloper') || $self->userValue('showDesigner') ) {
2363
2364 if ( $self->formValue( 'pageAction' ) eq "installCore") {
2365
2366 #
2367 # We only want the end part of the package for the file name
2368 #
2369 my $distFile = 'V2.pm';
2370 my $newV2File = $self->{fileSecurePath} . "/FWS/" . $distFile;
2371
2372 #
2373 # get the stuff ready for the backup copy info
2374 #
2375 require File::Copy;
2376 File::Copy->import();
2377 my $currentTime = $self->formatDate( format => 'number' );
2378
2379 $self->FWSLog("Backing up FWS core: " . $newV2File . " - Backup File Is Now: " . $newV2File . "." . $currentTime);
2380 copy( $newV2File, $newV2File . "." . $currentTime );
2381  
2382 my ( $updateString, $majorVer, $minorVer, $build ) = $self->_versionData( 'live', 'core', 'fws_installCore' );
2383  
2384 #
2385 # set the base URL for where the dist files are pulled from
2386 #
2387 my $imageBaseURL = $self->{FWSServer} . '/fws_' . $majorVer;
2388  
2389 #
2390 # get the core Script
2391 #
2392 if ( $self->_pullDistFile( $imageBaseURL . '/current_frameworksitescom.pm', $self->{fileSecurePath} . '/FWS', $distFile, "package FWS::V2;\n" ) ) {
2393
2394 #
2395 # import the new core admin
2396 #
2397 $self->_importAdmin( 'current_core' );
2398 $self->FWSLog( 'FWS core element packages updated' );
2399 $self->formValue( 'coreStatusNote', 'Current FWS Core element and file packages has been updated' );
2400
2401 #
2402 # flg our sucess swo we can save versionData
2403 #
2404 $self->_versionData( 'live', 'core', 'fws_installCore', 1 );
2405  
2406 #
2407 # add the fwsdemo files if they are not there already
2408 #
2409 my $demoFile = $self->{fileSecurePath} . '/backups/fwsdemo';
2410 if ( !-e $demoFile . '.sql' ) {
2411 $self->_pullDistFile( $imageBaseURL . '/fwsdemo.sql', $self->{fileSecurePath} . '/backups', 'fwsdemo.sql', '' );
2412 }
2413 if ( !-e $demoFile . '.files' ) {
2414 $self->_pullDistFile( $imageBaseURL . '/fwsdemo.files', $self->{fileSecurePath} . '/backups', 'fwsdemo.files', '' );
2415 }
2416
2417 #
2418 # delete cache directory
2419 #
2420 $self->flushWebCache();
2421  
2422 #
2423 # get rid of any orphaned data from the install process
2424 #
2425 $self->_deleteOrphanedData( "data", 'guid', "guid_xref", "child");
2426  
2427 #
2428 # if there is no elements on the site yet lets install our demo site
2429 #
2430 if ( !@{$self->runSQL( SQL => "select 1 from data where site_guid not like 'f%' and guid not like 'h%'" )} ) {
2431 $self->restoreFWS( id => 'fwsdemo' );
2432 print "Status: 302 Found\n";
2433 print "Location: " . $self->{scriptName} . "\n\n";
2434  
2435 }
2436 }
2437 }
2438  
2439  
2440 if ( $self->formValue( 'pageAction' ) eq "FWSBackup") {
2441  
2442 my $backupID = $self->backupFWS(
2443 excludeSiteFiles => ( $self->formValue('excludeSiteFiles') eq 'true' ) ? 1 : 0,
2444 id => $self->formValue('backupName'),
2445 excludeTables => 'zipcode,country,cart,geo_block,' . $self->{FWSBackupExcludeTables},
2446 );
2447  
2448 $self->formValue('backupStatusNote','Backup completed using backup name '.$backupID);
2449 }
2450  
2451 if ( $self->formValue( 'pageAction' ) eq "clearFWSLog") {
2452 unlink $self->{fileSecurePath} . '/FWS.log';
2453 $self->formValue("logStatusNote", "The FWS.log file was cleared");
2454 }
2455  
2456 if ( $self->formValue( 'pageAction' ) eq "flushSessions") {
2457 if ( $self->formValue( 'months' ) ne '' ) {
2458 $self->runSQL( SQL => "delete from fws_sessions where created < '" . $self->formatDate( format => 'SQL', monthMod => -( $self->formValue( 'months' ) ) ) . "'");
2459 if ( $self->DBType() =~ /^mysql$/i ) { $self->runSQL( SQL => "optimize table fws_sessions" ) }
2460 $self->formValue( "sessionStatusNote", "Your sessions table was optimized" );
2461 }
2462 }
2463  
2464 if ( $self->formValue( 'pageAction' ) eq "flushSearchCache") {
2465 my ( $dataUnits ) = $self->flushSearchCache( $self->{siteGUID} ) ;
2466 $self->formValue( "statusNote", "Your search cache was rebuilt using a total of " . $dataUnits . " records.");
2467 }
2468
2469 if ( $self->formValue( 'pageAction' ) eq "flushWebCache") {
2470 $self->flushWebCache();
2471 $self->formValue( "statusNote", "Your web search cache was emptied" );
2472 }
2473
2474 }
2475  
2476 return;
2477 }
2478  
2479 sub _pullDistFile {
2480 my ( $self, $imageURL, $directory, $distFile, $preContent ) = @_;
2481  
2482 require LWP::UserAgent;
2483 my $browser = LWP::UserAgent->new();
2484 my $response = $browser->get( $imageURL );
2485 if (!$response->is_success ) {
2486 $self->FWSLog( "FWS server connection error: " . $response->status_line );
2487 $self->formValue( 'coreStatusNote', "A network error in connecting to FWS Server:" . $response->status_line );
2488 return 0;
2489 }
2490  
2491 #
2492 # we got it! lets save it
2493 #
2494 $self->makeDir( $directory );
2495 open ( my $FILE, ">", $directory . '/' . $distFile );
2496 print $FILE $preContent . $response->content;
2497 close $FILE;
2498
2499 $self->FWSLog( "FWS secure distributed file saved: " . $directory . '/' . $distFile );
2500 return 1;
2501 }
2502  
2503 sub _addTemplate {
2504 my ( $self, $siteGUID, $title, $templateDevel, $cssDevel, $jsDevel, $default_template ) = @_;
2505 #
2506 # switch the title to sql frienldy, and then insert the data
2507 # switch the css, and java on the fly, because we don't want it changed before we save it to
2508 # a file
2509 #
2510 $title = $self->safeSQL( $title );
2511 my $guid = $self->createGUID( 't' );
2512
2513 #
2514 # set defaults
2515 #
2516 $default_template ||= 0;
2517
2518 $self->runSQL( SQL => "insert into templates (guid,site_guid,title,template_devel,default_template) values ('" . $guid . "','" . $self->safeSQL($siteGUID) . "','" . $title . "','" . $self->safeSQL($templateDevel) . "','" . $self->safeSQL($default_template) . "')" );
2519  
2520 #
2521 # create the files if we need to
2522 #
2523 if ( $jsDevel ) {
2524 $self->_saveElementFile( $guid, $siteGUID, 'template', 'js', $jsDevel );
2525 }
2526 if ( $cssDevel ) {
2527 $self->_saveElementFile( $guid, $siteGUID, 'template', 'css', $cssDevel );
2528 }
2529 return $guid;
2530 }
2531  
2532 sub _getHighlightColor {
2533 my ( $self, $inColor, $percent ) = @_;
2534 $percent ||= 90;
2535 $percent = $percent / 100;
2536 $inColor =~ s/[^0-9a-fA-F]//sg;
2537 my @colorArray = split( //, $inColor );
2538 my $RC = hex( $colorArray[0] . $colorArray[1] );
2539 my $GC = hex( $colorArray[2] . $colorArray[3] );
2540 my $BC = hex( $colorArray[4] . $colorArray[5] );
2541 $RC = sprintf( "%x", int( ( 255 - $RC ) * $percent) + $RC );
2542 $GC = sprintf( "%x", int( ( 255 - $GC ) * $percent) + $GC );
2543 $BC = sprintf( "%x", int( ( 255 - $BC ) * $percent) + $BC );
2544 return "#" . $RC . $GC . $BC;
2545 }
2546  
2547 #
2548 # easy reuse optoin sub for the fws_data_edit
2549 #
2550 sub _createOptionGroup {
2551 my ( $self, $optLabel, $ordMin, $ordMax, %elementHash ) = @_;
2552  
2553 #
2554 # for elements in there twice because they are present via the guid, and the elementType lets hold a hash so we don't dup them
2555 #
2556 my %elementDisplayed;
2557 my $optionFullHTML = "<optgroup label=\"" . $optLabel . "\">";
2558 for my $guid ( sort { $elementHash{$a}{alphaOrd} <=> $elementHash{$b}{alphaOrd} } keys %elementHash) {
2559 if ( !$elementDisplayed{$elementHash{$guid}{guid}} && ( !$elementHash{$guid}{parent} || $elementHash{$guid}{rootElement} ) && $elementHash{$guid}{ord} > $ordMin && $elementHash{$guid}{ord} <= $ordMax ) {
2560 $optionFullHTML .= "<option value=\"" . $guid . "\">" . $elementHash{$guid}{title} . "</option>";
2561
2562 #
2563 # set the flag that we have seen this one aready, we don't need two of them!
2564 #
2565 $elementDisplayed{$elementHash{$guid}{guid}} = 1;
2566 }
2567 }
2568 $optionFullHTML .= "</optgroup>";
2569 return $optionFullHTML;
2570 }
2571  
2572
2573 sub _createLineMap {
2574 my ( $self, %paramHash ) = @_;
2575 my $lineHTML;
2576 #
2577 # Split up the map into an array and set the default icon
2578 #
2579 my @lineMap = split(//,$paramHash{lineMap});
2580  
2581 while (@lineMap) {
2582 my $idHTML;
2583 my $icon = "blank.gif";
2584 my $lineChar = shift(@lineMap);
2585  
2586 #
2587 # set the default icons
2588 #
2589 if ( $lineChar eq '|' ) { $icon = 'line.gif' }
2590 if ( $lineChar eq '+' ) { $icon = 'joinbottom.gif' }
2591 if ( $lineChar eq 'L' ) { $icon = 'join.gif'; $paramHash{lastInList} = 1 }
2592  
2593 #
2594 # if there is an expand use these icons, and set the anchor wrapper
2595 #
2596 if ( $paramHash{expandQuery} ) {
2597 if ($lineChar eq '+') { $icon = 'plusbottom.gif' }
2598 if ($lineChar eq 'L') { $icon = 'plus.gif'}
2599 if ($lineChar eq 'L' || $lineChar eq '+') {
2600 $idHTML = "id=\"tree" . $paramHash{id} . "\"";
2601 }
2602 }
2603 $lineHTML .= "<img class=\"FWSTreeEventRowImage\" alt=\"\" src=\"" . $self->{fileFWSPath} . "/" . $icon . "\" " . $idHTML . "/>";
2604 }
2605 return $lineHTML
2606 }
2607  
2608 sub _editModeLink {
2609 my ( $self, $conName, $linkSpacer ) = @_;
2610 my $hideConCSSJS = "\$('#" . $conName . "').hide('slow');";
2611 if ( $self->formValue( "p" ) !~ /^fws_/) {
2612 return $self->_selfWindow( "editMode=" . ( $self->formValue( 'editMode' ) ? 0 : 1 ) . "&p=" . $self->formValue( "p" ) . "&id=" . $self->formValue( "id" ), ( $self->formValue( 'editMode' ) ? 'Live' : 'Edit' ) . "&nbsp;Mode", $hideConCSSJS ) . $linkSpacer;
2613 }
2614 }
2615  
2616 sub _logOutLink {
2617 my ( $self, $conName ) = @_;
2618 my $hideConCSSJS = "\$('#" . $conName . "').hide('slow');";
2619 return $self->_selfWindow( "pageAction=adminLogOut&p=0", "Log&nbsp;Out", $hideConCSSJS );
2620 }
2621  
2622 sub _packageLine {
2623 my ( $self, $name, $currentVer, $newVer, $script ) = @_;
2624 my $line = "<tr>";
2625 my $upText = "Upgrade";
2626  
2627 if ( !$currentVer ) { $currentVer = "Not Installed"; $upText = "Install" }
2628 if ( $currentVer eq $newVer ) { $upText = "Re-Install" }
2629 $line .= "<td>" . $name . "</td>";
2630  
2631 $line .= "<td style=\"text-align:center;width:200px;\">" . $currentVer . "</td>";
2632 $line .= "<td style=\"text-align:center;width:200px;\">" . $newVer . "</td>";
2633 $line .= "<td style=\"text-align:center;width:100px;\"><a href=\"" . $self->{scriptName} . $self->{queryHead} . "p=" . $script . "\">" . $upText . "</a>";
2634 $line .= "</tr>";
2635 return $line;
2636 }
2637  
2638  
2639 sub _checkScript {
2640 my ( $self, $moduleName ) = @_;
2641 my $errorReturn;
2642  
2643 if ( !$self->{FWSScriptCheck}->{registerPlugins} ) { $errorReturn .= '<li>Your script file is missing $fws->registerPlugins(); this should be added.</li>' }
2644  
2645 if ( $errorReturn ) { $errorReturn = '<ul>' . $errorReturn . '</ul>' }
2646 return $errorReturn;
2647 }
2648  
2649  
2650  
2651 sub _checkIfModuleInstalled {
2652 my ( $self, $moduleName ) = @_;
2653 my $errorReturn;
2654  
2655 ## no critic
2656 eval "use " . $moduleName;
2657 ## use critic
2658  
2659 if ( $@ ) {
2660 my $bump;
2661 if ($moduleName eq "Google::SAML::Response") { $bump = $moduleName . " is used for Single Sign On Google Apps integration. If your not using this website for Google SSO then you will not need this." }
2662 if ($moduleName eq "Crypt::SSLeay") { $bump = $moduleName . " is used for secure transactions to payment gateways. If your not using eCommerce real time payment gateways this module may not be necessary." }
2663 if ($moduleName eq "Captcha::reCAPTCHA") { $bump = $moduleName . " is used for captcha support. If you are not using captchas for human form postings validation then this is not required." }
2664 if ($moduleName eq "Crypt::Blowfish") { $bump = $moduleName . " is used to encrypt tranasactional data. If your not using eCommerce real time payment gateways this module may not be necessary." }
2665 $errorReturn .= "<ul><li>" . $moduleName . " Perl module missing. Your site may not run correctly without it. " . $bump . "<br/><br/><ul><li>To install it if you have shell access you can do the following:<br/>server prompt> cpan<br/>CPAN> install " . $moduleName . "<br/><i>Note: You must be logged in as root to use cpan, if you are unfamiliar with using cpan it might be best to have a system adminstrator do this for you.</i></li><li>To install it from CPanel do the following:<br/>Perl Modules -> Install a Perl Module: " . $moduleName . "</li><li>If these methods are unavailable you may need your server administrator to install it for you.</li></ul></li></ul><br/>" }
2666  
2667 return $errorReturn;
2668 }
2669  
2670 sub _systemInfoCheckDir {
2671 my ( $self, $newDir ) = @_;
2672  
2673 my $errorReturn;
2674 my $documentRoot = $ENV{DOCUMENT_ROOT};
2675 my $scriptFilename = $ENV{SCRIPT_FILENAME};
2676  
2677 if ( !-e $newDir ) {
2678 if ( $newDir =~ /\/fws/ ) {
2679 if ( !$self->{hideFWSCoreUpgrade} ) {
2680 $errorReturn .= "Your core element and file package is not installed yet.<br/>";
2681 $errorReturn .= '<a href="' . $self->{scriptName} . '?p=fws_systemInfo&pageAction=installCore">Click here to install your core element and file package</a><br/>';
2682 $errorReturn .= '<i>Depending on your connection speed and server performance, your page may take a few minutes to load after clicking the link below.</i>';
2683 }
2684 }
2685 else {
2686 $errorReturn .= "<ul><li>The directory '" . $newDir . "' does not exist";
2687 $self->makeDir( $newDir );
2688 if ( !-e $newDir ) {
2689 $errorReturn .= ". The webserver does not have permissions to create this directory.<br/>Create this directory by hand, and make it web server writable. <ul><li>Sometimes large ISP might have complex directories. Usually it will match in part with one of these, but not always:<br/>Document Root: " . $documentRoot . "<br/>Script Root Path: " . $scriptFilename . "</li><li>You can change your file permissions from your server console using: chmod 755 " . $newDir . "<br/>This can also be done though web based server administration programs or even FTP if your security settings will allow it.</li></ul>";
2690 }
2691 else {
2692 $errorReturn .= ',&nbsp;but was created automaticly.</br> <a href="' . $self->{scriptName} . '?p=fws_systemInfo">Click here to continue system health check</a>';
2693 }
2694 }
2695 $errorReturn .= "</li></ul><br/>";
2696 }
2697 else {
2698 if ( !$self->_testDirWritePermission( $newDir ) ) {
2699 $errorReturn .= "<ul><li>The directory '" . $newDir . "' is not web server writable.<br/>";
2700 $errorReturn .= "<ul><li>Usually this means changing your file permissions for this directly using: chmod 755 " . $newDir . "</li><li>chmod style permissions can also be done though web based server administration programs or even FTP if your security settings will allow it.</li><li>Some configurations my require an administrator to change the ownership of this directory to the webserver by using: chown nobody:nobody " . $newDir . " ('nobody:nobody' is a default web server user and group, it could be 'www:www' or something different)</li></ul>";
2701 $errorReturn .= "</li></ul><br/>";
2702 }
2703 }
2704 return $errorReturn;
2705 }
2706  
2707 sub _testDirWritePermission {
2708 my ( $self, $testFile ) = @_;
2709 $testFile .= "/testfile.tmp";
2710 open ( my $FILE, ">", $testFile );
2711 print $FILE "TEST FILE";
2712 close $FILE;
2713 if ( -e $testFile ) {
2714 unlink $testFile;
2715 return 1;
2716 }
2717 return 0;
2718 }
2719  
2720 sub _sessionInfo {
2721 my ( $self, %paramHash ) = @_;
2722 my %returnHash;
2723 ( $returnHash{total} ) = @{$self->runSQL( SQL => "select count(1) from fws_sessions" )};
2724 ( $returnHash{1} ) = @{$self->runSQL( SQL => "select count(1) from fws_sessions where created < '" . $self->formatDate( format => 'SQL', monthMod=>-1 ) . "'" )};
2725 ( $returnHash{3} ) = @{$self->runSQL( SQL => "select count(1) from fws_sessions where created < '" . $self->formatDate( format => 'SQL', monthMod=>-3 ) . "'" )};
2726 return %returnHash;
2727 }
2728  
2729  
2730 sub _importAdmin {
2731 my ($self,$adminFile) = @_;
2732 my $removeCore = 0;
2733 my $keepAlive = 500;
2734 if ( $adminFile eq 'current_core' ) {
2735 $removeCore = 1;
2736 $keepAlive = 0;
2737 }
2738 return $self->importSiteImage(
2739 newSID => "fws",
2740 imageURL => "http://www.frameworksites.com/downloads/fws_" . $self->{FWSVersion} . "/" . $adminFile . ".fws",
2741 removeCore => $removeCore,
2742 parentSID => "admin",
2743 keepAlive => $keepAlive,
2744 );
2745 }
2746  
2747  
2748 sub _installZipcode {
2749 my ( $self ) = @_;
2750  
2751 #
2752 # make stdout hot! and start sending to browser
2753 #
2754 local $| = 1;
2755 print $self->_installHeader( 'Zipcode' );
2756  
2757 $self->runSQL(SQL=>"delete from zipcode");
2758  
2759 print "<br/>Downloading and Installing";
2760
2761 my $importReturn = $self->_importAdmin( 'current_zipcode' );
2762
2763 print "<br/>" . $importReturn;
2764  
2765 print $self->_installFooter( 'Zipcode' );
2766
2767 if ( $importReturn !~ /error/i ) { $self->_versionData( 'live', 'zipcode', "fws_installZipcode", 1 ) }
2768
2769 $self->{stopProcessing} = 1;
2770  
2771 return;
2772 }
2773
2774 sub _installCountry {
2775 my ( $self ) = @_;
2776
2777 #
2778 # make stdout hot! and start sending to browser
2779 #
2780 local $| = 1;
2781 print $self->_installHeader( 'Country' );
2782
2783 $self->runSQL( 'delete from country' );
2784
2785 print "<br/>Downloading and Installing";
2786  
2787 my $importReturn = $self->_importAdmin( 'current_country' );
2788
2789 print $self->_installFooter( 'Country' );
2790
2791 if ( $importReturn !~ /error/i ) { $self->_versionData( 'live', 'country', "fws_installCountry", 1 ) }
2792
2793 $self->{stopProcessing} = 1;
2794  
2795 return;
2796 }
2797  
2798 sub _installHeader {
2799 my ( $self, $name ) = @_;
2800 return "Content-Type: text/html; charset=UTF-8\n\n<html><head><title>Installing New " . $name . " Package</title>" .
2801 "</head>".
2802 "<body><h2>Installing New " . $name . " Package</h2><br/>".
2803 "<b>" . $name . " Package</b><hr/>".
2804 "Doing pre install cleanup";
2805 }
2806  
2807 sub _installFooter {
2808 my ( $self, $name ) = @_;
2809 return "<br/><br/>Finished: <a href=\"" . $self->{scriptName} . $self->{queryHead} . "p=fws_systemInfo\">Click here to continue</a></body></html>";
2810 }
2811  
2812 =head2 uploadSiteFile
2813  
2814 Execute a file upload from a form post.
2815  
2816 =cut
2817  
2818 sub uploadSiteFile {
2819 my ( $self, %paramHash ) = @_;
2820  
2821 #
2822 # move the passed vars into regular vars because we might want to use this paramHash to do a saveData
2823 # and don't want any relics
2824 #
2825 my $secureFile = $paramHash{FWSSecureFile};
2826 my $uploadFileField = $paramHash{FWSUploadFileField};
2827 my $uploadField = $paramHash{FWSUploadField};
2828 delete $paramHash{FWSUploadFileField};
2829 delete $paramHash{FWSUploadField};
2830 delete $paramHash{FWSSecureFile};
2831  
2832 #
2833 # get the file name and also name the "name" file that. The "name" could be
2834 # replaced with the name extField if it is not blank. But this will ensure
2835 # that the name is populated with at least something
2836 #
2837 my @fileArray = $self->formValue( $uploadFileField );
2838  
2839 #
2840 # set site guid if it wasn't passed
2841 #
2842 $paramHash{siteGUID} ||= $self->{siteGUID};
2843  
2844 #
2845 # process each one (I think this doesn't actually send more than one because of the uploader we use
2846 # , but hey, might as well!
2847 #
2848 foreach my $fileHandle ( @fileArray ) {
2849  
2850 my $runFileCleanup = 0;
2851  
2852 #
2853 # clean up the file name, and make sure the dirs are safe before we do anything with them
2854 #
2855 $paramHash{name} = $self->justFileName( $self->formValue( $uploadFileField ) );
2856 $paramHash{name} = $self->safeDir( $paramHash{name} );
2857  
2858 #
2859 # we have a parent... but we don't ahve a guid, this is a subrecord
2860 #
2861 if ( $paramHash{parent} && !$paramHash{guid} ) {
2862 #
2863 # save the record so we have a guid
2864 #
2865 %paramHash = $self->saveData( %paramHash );
2866  
2867 #
2868 # now that we know the guid, lets set the file name
2869 #
2870 $paramHash{$uploadField} = $self->{fileWebPath} . '/' . $self->{siteGUID} . '/' . $paramHash{guid} . '/' . $paramHash{name};
2871 %paramHash = $self->saveData(%paramHash);
2872  
2873 #
2874 # because we are saving a record lets flag this so we do image cleanup at the end
2875 #
2876 $runFileCleanup = 1;
2877 }
2878  
2879 #
2880 # set the directory
2881 #
2882 my $directory = '/' . $paramHash{siteGUID} . '/' . $paramHash{guid} . '/';
2883 if ( $secureFile ) { $directory = $self->{fileSecurePath} . '/files/' . $directory }
2884 else { $directory = $self->{filePath} . $directory }
2885 $directory = $self->safeDir( $directory );
2886  
2887 #
2888 # make the directory if its not already there
2889 #
2890 $self->makeDir( $directory );
2891 $self->uploadFile( $directory, $fileHandle, $paramHash{name} );
2892  
2893 #
2894 # comptabality keys to match those in fileArray
2895 #
2896 $paramHash{fullFile} = $directory . '/' . $paramHash{name};
2897 $paramHash{file} = $paramHash{name};
2898  
2899 #
2900 # if we are adding new records redo any of the image thumbs and such and lets delete the guid so we can get a fresh one if there is another pass
2901 #
2902 if ( $runFileCleanup ) {
2903 $self->createSizedImages( guid => $paramHash{guid} );
2904 delete $paramHash{guid};
2905 }
2906 }
2907 return %paramHash;
2908 }
2909  
2910 sub _convertImportTags {
2911 my ( $self, %paramHash ) = @_;
2912  
2913 my $conversionString = $paramHash{content};
2914 my $siteGUID = $paramHash{siteGUID};
2915 my $scriptName = $self->{scriptName};
2916 my $domain = $self->{domain};
2917 my $secureDomain = $self->{secureDomain};
2918 my $fileWebPath = $self->{fileWebPath};
2919  
2920 #
2921 # clean and format the data from the import storage
2922 #
2923 $conversionString =~ s/#FWSSiteGUID#/$siteGUID/sg;
2924 $conversionString =~ s/#FWSDomain#/$domain/sg;
2925 $conversionString =~ s/#FWSScriptName#/$scriptName/sg;
2926 $conversionString =~ s/#FWSSecureDomain#/$secureDomain/sg;
2927 $conversionString =~ s/#FWSFileWebPath#/$fileWebPath/sg;
2928 return $conversionString;
2929 }
2930  
2931  
2932 =head1 AUTHOR
2933  
2934 Nate Lewis, C<< <nlewis at gnetworks.com> >>
2935  
2936 =head1 BUGS
2937  
2938 Please report any bugs or feature requests to C<bug-fws-v2 at rt.cpan.org>, or through
2939 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FWS-V2>. I will be notified, and then you'll
2940 automatically be notified of progress on your bug as I make changes.
2941  
2942  
2943  
2944  
2945 =head1 SUPPORT
2946  
2947 You can find documentation for this module with the perldoc command.
2948  
2949 perldoc FWS::V2::Admin
2950  
2951  
2952 You can also look for information at:
2953  
2954 =over 4
2955  
2956 =item * RT: CPAN's request tracker (report bugs here)
2957  
2958 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FWS-V2>
2959  
2960 =item * AnnoCPAN: Annotated CPAN documentation
2961  
2962 L<http://annocpan.org/dist/FWS-V2>
2963  
2964 =item * CPAN Ratings
2965  
2966 L<http://cpanratings.perl.org/d/FWS-V2>
2967  
2968 =item * Search CPAN
2969  
2970 L<http://search.cpan.org/dist/FWS-V2/>
2971  
2972 =back
2973  
2974  
2975 =head1 LICENSE AND COPYRIGHT
2976  
2977 Copyright 2013 Nate Lewis.
2978  
2979 This program is free software; you can redistribute it and/or modify it
2980 under the terms of either: the GNU General Public License as published
2981 by the Free Software Foundation; or the Artistic License.
2982  
2983 See http://dev.perl.org/licenses/ for more information.
2984  
2985  
2986 =cut
2987  
2988 1; # End of FWS::V2::Admin