/
compiler.php
621 lines (564 loc) · 22.8 KB
/
compiler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
<?php
// Copyright: All contributers to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license
//
// Invoked on the UmpleOnline server to cause one of the
// two jars to be run with appropriate arguments (umple.jar or umplesync.jar)
//
// Involed as an Ajax call by umple_action.js in the following places:
// Action.ajax - near the end of that file - for most compilation tasks
// Action.loadFile using ajax.js - argument load - load a user saved file
// Action.loadExample - argument exampleCode - one of the pre-canned examples
// Action.saveNewFile using ajax.js - argument save
// Action.pngImage, Action.ymlImageCallback
// Action.uiguCallback - argument asUI
//
// This file also formats the output from the jars for presentation back on
// the UmpleOnline screen
//
// Most of the helper methods are in compiler_config.php, except
// getErrorHtml, which reads the generated error file, and jsonDecode
//
require_once("compiler_config.php");
// Allow CORS so that any site may use the Umple compiler.
header("Access-Control-Allow-Origin: *");
if (isset($_REQUEST["save"]))
{
if(isset($_REQUEST["svgContent"]))
{
$input = $_REQUEST["svgContent"];
if(isset($_REQUEST["filename"]))
{
$filename = basename($_REQUEST['filename']);
$modelId = dirname($_REQUEST['filename']);
$dataHandle = dataStore()->openData($modelId);
$dataHandle->writeData($filename, $input);
}
else
{
// this makes no sense, but mimic old behaviour for now
$filename = 'model.ump';
$dataHandle = dataStore()->createData();
$dataHandle->writeData($filename, $input);
}
$workDir = $handleData->getWorkDir();
// it will inserted into an href, so we should actually permalink
// the resulting file
echo $workDir->makePermalink($filename);
}
else
{
$input = $_REQUEST["umpleCode"];
list($dataname, $dataHandle) = getOrCreateDataHandle();
if (isset($_REQUEST["lock"]) && isset($_REQUEST["model"])){
$model = $_REQUEST["model"];
$lock_file = "../ump/".$model."/.lockfile";
$fp = fopen($lock_file, "w");
if (flock($fp, LOCK_EX)) {
try {
$dataHandle->writeData($dataname, $input);
} catch (Exception $e) {
// Do nothing for now here
} finally {
flock($fp, LOCK_UN);
}
}
}
else
{
$dataHandle->writeData($dataname, $input);
}
// pretend this is still the old system and mimic the kind of path
// the JavaScript expects
echo '../ump/'.$dataHandle->getName().'/'.$dataname;
}
}
else if (isset($_REQUEST["load"]))
{
// extract the model ID and filename from the old-style path
$filename = basename($_REQUEST["filename"]);
$modelId = basename(dirname($_REQUEST["filename"]));
$dataHandle = dataStore()->openData($modelId);
$outputUmple = $dataHandle->readData($filename);
echo $outputUmple;
}
else if (isset($_REQUEST["action"]))
{
handleUmpleTextChange();
}
else if (isset($_REQUEST["umpleCode"]))
{
$input = $_REQUEST["umpleCode"];
$fulllanguage = $_REQUEST["language"];
// If there are suboptions in the language string, parse them out
// Language stringh could be cpp or cpp.opt1.opt2.opt3
$langparts = explode('.',$fulllanguage);
$language = $langparts[0];
$suboptions = "";
for($i=1; $i<count($langparts); $i++){
$suboptions = $suboptions . " -s " . $langparts[$i];
}
$languageStyle = isset($_REQUEST["languageStyle"])?
$_REQUEST["languageStyle"] : false;
$outputErr = isset($_REQUEST["error"])?$_REQUEST["error"]:false;
$uigu = False;
$javadoc = false;
$stateDiagram = false;
$featureDiagram = false;
$classDiagram = false;
$entityRelationshipDiagram = false;
$yumlDiagram = false;
$uigu = false;
$Uigu2 = false;
$htmlContents = false;
$generatorType = "";
//featureDiagram
if ($language == "javadoc")
{
$language = "Java";
$javadoc = True;
}
else if ($language == "stateDiagram")
{
$language = "GvStateDiagram";
$generatorType = "";
$stateDiagram = True;
}
else if ($language == "featureDiagram")
{
$language = "GvFeatureDiagram";
$generatorType = "";
$featureDiagram = True;
}
else if ($language == "classDiagram")
{
$language = "GvClassDiagram";
$generatorType = "cd";
$classDiagram = True;
}
else if ($language == "traitDiagram")
{
$language = "GvClassTraitDiagram";
$generatorType = "cdt";
$classDiagram = True;
}
else if ($language == "entityRelationshipDiagram")
{
$language = "GvEntityRelationshipDiagram";
$generatorType = "erd";
$entityRelationshipDiagram = True;
}
else if ($language == "yumlDiagram")
{
$language = "Yuml";
$yumlDiagram = True;
}
else if ($language == "uigu")
{
$language = "Uigu";
$uigu = True;
}
else if ($language == "Uigu2")
{
$Uigu2 = True;
$htmlContents = True;
}
if ($languageStyle == "html")
{
$htmlContents = true;
}
if ($language == "Simulate")
{
list($dataname, $dataHandle) = getOrCreateDataHandle();
$dataHandle->writeData($dataname, "generate Php \"./\" --override-all;\n" . $input);
$workDir = $dataHandle->getWorkDir();
$filename = $workDir->getPath().'/'.$dataname;
executeCommand("java -jar umple.jar {$filename}");
$workDir->saveModel();
$dataHandle->writeData($dataname, "generate Simulate \"./\" --override-all;\n" . $input);
$workDir = $dataHandle->getWorkDir();
$filename = $workDir->getPath().'/'.$dataname;
executeCommand("java -jar umple.jar {$filename}");
$workDir->saveModel();
// Restore file so it doesn't have the 'generate' command in front
$dataHandle->writeData($dataname, $input);
echo $dataHandle->getName();
return;
}
elseif ($uigu)
{
list($dataname, $dataHandle) = getOrCreateDataHandle();
$dataHandle->writeData($dataname, $input);
$workDir = showUserInterface($dataname, $dataHandle);
/* chdir("JSFProvider");
if (file_exists("JSFProvider/model.ump"))
unlink("JSFProvider/model.ump");
copy("$filename", "JSFProvider/model.ump");
executeCommand("java -cp GUIModel.jar;JSFProvider.jar;GUIGenerator.jar cruise.generator.UIGU UmpleProject.xml model.ump TempDir TempApp");*/
}
else if ($htmlContents) {
list($dataname, $dataHandle) = getOrCreateDataHandle();
$dataHandle->writeData($dataname, $input);
$workDir = $dataHandle->getWorkDir();
$filename = $workDir->getPath().'/'.$dataname;
// note: this does not create the error output in the working directory, and likely never did
$errorFilename = "{$filename}.erroroutput";
$sourceCode = executeCommand("java -jar umplesync.jar -generate {$language} {$filename} 2> {$errorFilename}");
$errors = getErrorHtml($errorFilename, 0);
if($outputErr == "true")
echo $errors . "<p>URL_SPLIT";
$workDir->saveModel();
if($Uigu2) {
$uigu2dir = $workDir->getPath();
if (!file_exists($uigu2dir."/app")) {
symlink("../../scripts/uigu2/app",$uigu2dir."/app");
}
// exec("cd $uigu2dir; ln -s ../../scripts/uigu2/app .");
$uigu2file = $workDir->makePermalink('index.php');
// DEBUG - to display as a link Uncomment the following line, and comment out the subsequent 4
// $html = "{$errhtml} <b> <a target=\"otherone\" href=\"" . $uigu2file . "\">$uigu2file</a> </b>";
$html = "
<iframe width=100% height=1000 src=\"" . $uigu2file . "\">This browser does not
support iframes, so the uigu cannot be displayed</iframe>
";
echo $html;
}
else {
echo $sourceCode;
}
return;
} // end html content
elseif (!in_array($language,array("Php","Java","Ruby","RTCpp","Cpp","Sql","GvFeatureDiagram","GvStateDiagram","GvClassDiagram","GvEntityRelationshipDiagram","GvClassTraitDiagram","Yuml")))
{ // If NOT one of the basic languages, then use umplesync.jar
list($dataname, $dataHandle) = getOrCreateDataHandle();
$dataHandle->writeData($dataname, $input);
$workDir = $dataHandle->getWorkDir();
$filename = $workDir->getPath().'/'.$dataname;
$errorFilename = "{$filename}.erroroutput";
if ($language == "Experimental-Cpp" || $language == "Experimental-Sql") {
$sourceCode = executeCommand("echo \"{$language} is under development. Output is currently only available to developers of Umple\" 2> {$errorFilename}");
}
else {
$sourceCode = executeCommand("java -jar umplesync.jar -generate {$language} {$filename} 2> {$errorFilename}");
}
$errors = getErrorHtml($errorFilename, 0);
if ($language != "Json" && $language != "JsonMixed")
{
$sourceCode = htmlspecialchars($sourceCode);
}
if($outputErr == "true")
echo $errors ."<p>URL_SPLIT";
$workDir->saveModel();
echo $sourceCode;
return;
}
if (!$uigu)
{ // NOTuigu
// Generate the Java, PHP, RTCpp, Ruby, Cpp or Sql and put it into the right directory
list($dataname, $dataHandle) = getOrCreateDataHandle();
$dataHandle->writeData($dataname, "generate {$language} \"./{$language}/\" --override-all;\n" . $input);
$workDir = $dataHandle->getWorkDir();
$filename = $workDir->getPath().'/'.$dataname;
$outputFilename = "{$filename}.output";
$errorFilename = "{$filename}.erroroutput";
// Clean up any pre-existing java. php, RTCpp, ruby or cpp files
$thedir = dirname($outputFilename);
$toRemove = False;
$rmcommand = "rm -rf ";
foreach (glob("$thedir/{$language}") as $afile) {
$rmcommand = $rmcommand . " " . $afile;
$toRemove = True;
}
if($toRemove) { exec($rmcommand); }
// The following is a hack. The arguments to umplesync need fixing
if (!$stateDiagram && !$classDiagram && !$entityRelationshipDiagram && !$yumlDiagram && !$featureDiagram) {
$command = "java -jar umplesync.jar -source {$filename} 2> {$errorFilename}";
}
else {
// The following is used for outputting diagrams only
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/modelcd.gv " . $thedir . "/model.gv " . $thedir . "modelcdt.gv " . $thedir . "/modelerd.gv");
$command = "java -jar umplesync.jar -generate " . $language . " {$filename} " . $suboptions . " 2> {$errorFilename}";
}
// Took off 1> {$outputFilename} in two commands above
$resultFromCommand = executeCommand($command);
$dataHandle->writeData(basename($outputFilename), $resultFromCommand);
//exec("( ulimit -t 10; " . $command . ")");
// Restore file so it doesn't have the 'generate' command in front
$dataHandle->writeData($dataname, $input);
$sourceCode = $resultFromCommand;
$sourceCode = str_replace("<?php","",$sourceCode);
$sourceCode = str_replace("?>","",$sourceCode);
$sourceCode = htmlspecialchars($sourceCode);
$errhtml = getErrorHtml($errorFilename);
if ($sourceCode == "")
{
if($input == "//$?[End_of_model]$?") {
$html = "
Please create an Umple model textually (on the left side of the screen)
or visually (on the right side of the screen),
and then choose Generate Code again.";
}
else
{
$html = "
An error occurred interpreting your Umple code, please review it and try again.
If the problem persists, please email the Umple code to
the umple-help google group: umple-help@googlegroups.com";
}
echo $errhtml ."<p>URL_SPLIT" . $html;
}
else
{
if ($javadoc)
{
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/javadoc");
$command = "javadoc -d " . $thedir . "/javadoc -footer \"Generated by Umple\" " ;
foreach (glob("$thedir/{$language}/*/*/*/*.java") as $afile) {
$command = $command . " " . $afile;
}
foreach (glob("$thedir/{$language}/*/*/*.java") as $afile) {
$command = $command . " " . $afile;
}
foreach (glob("$thedir/{$language}/*/*.java") as $afile) {
$command = $command . " " . $afile;
}
foreach (glob("$thedir/{$language}/*.java") as $afile) {
$command = $command . " " . $afile;
}
exec($command);
exec("cd $thedir; rm javadocFromUmple.zip; zip -r javadocFromUmple javadoc");
$javadocdir = $workDir->makePermalink('javadoc/');
$javadoczip = $workDir->makePermalink('javadocFromUmple.zip');
$html = "<a href=\"{$javadoczip}\">Download the following as a zip file</a> {$errhtml}
<iframe width=100% height=1000 src=\"" . $javadocdir . "\">This browser does not
support iframes, so the javadoc cannot be displayed</iframe>
";
echo $html;
} // end javadoc
else if ($stateDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/stateDiagram.svg");
$command = "dot -Tsvg -Gdpi=63 " . $thedir . "/model.gv -o " . $thedir . "/stateDiagram.svg";
exec($command);
if (!file_exists($thedir . "/stateDiagram.svg") && file_exists("doterr.svg"))
{
exec("cp " . "./doterr.svg " . $thedir . "/stateDiagram.svg");
}
$svgcode = readTemporaryFile("{$thedir}/stateDiagram.svg");
$svglink = $workDir->makePermalink('stateDiagram.svg');
$html = "<a href=\"umpleonline/$thedir/model.gv\">Download the GraphViz file for the following</a> <a href=\"$svglink\">Download the SVG file for the following</a> <br/>{$errhtml}
<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"2000\" width=\"2000\">";
echo $html;
echo $svgcode;
echo "</svg>";
} // end state diagram
else if ($featureDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/featureDiagram.svg");
$command = "dot -Tsvg -Gdpi=63 " . $thedir . "/modelGvFeatureDiagram.gv -o " . $thedir . "/featureDiagram.svg";
exec($command);
if (!file_exists($thedir . "/featureDiagram.svg") && file_exists("doterr.svg"))
{
exec("cp " . "./doterr.svg " . $thedir . "/featureDiagram.svg");
}
$svgcode = readTemporaryFile("{$thedir}/featureDiagram.svg");
$svglink = $workDir->makePermalink('featureDiagram.svg');
$html = "<a href=\featureDiagram.svg\">Download the GraphViz file for the following</a> <a href=\"$svglink\">Download the SVG file for the following</a> <br/>{$errhtml}
<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"2000\" width=\"2000\">";
echo $html;
echo $svgcode;
echo "</svg>";
}
else if ($classDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/classDiagram.svg");
$command = "dot -Tsvg -Gdpi=63 " . $thedir . "/model" . $generatorType . ".gv -o " . $thedir . "/classDiagram.svg";
exec($command);
if (!file_exists($thedir . "/classDiagram.svg") && file_exists("doterr.svg"))
{
exec("cp " . "./doterr.svg " . $thedir . "/classDiagram.svg");
}
$svgcode = readTemporaryFile("{$thedir}/classDiagram.svg");
$gvlink = $workDir->makePermalink('model'.$generatorType.'.gv');
$svglink = $workDir->makePermalink('classDiagram.svg');
$html = "<a href=\"$gvlink\">Download the GraphViz file for the following</a> <a href=\"$svglink\">Download the SVG file for the following</a> <br/>{$errhtml}
<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"2000\" width=\"2000\">";
echo $html;
echo $svgcode;
echo "</svg>";
} // end graphViz class diagram
else if ($entityRelationshipDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/entityRelationshipDiagram.svg");
$command = "dot -Tsvg -Gdpi=63 " . $thedir . "/modelerd.gv -o " . $thedir . "/entityRelationshipDiagram.svg";
exec($command);
if (!file_exists($thedir . "/entityRelationshipDiagram.svg") && file_exists("doterr.svg"))
{
exec("cp " . "./doterr.svg " . $thedir . "/entityRelationshipDiagram.svg");
}
$svgcode = readTemporaryFile("{$thedir}/entityRelationshipDiagram.svg");
$gvlink = $workDir->makePermalink('modelerd.gv');
$erdiagramlink = $workDir->makePermalink('entityRelationshipDiagram.svg');
$html = "<a href=\"$gvlink\">Download the GraphViz file for the following</a> <a href=\"$erdiagramlink\">Download the SVG file for the following</a> <br/>{$errhtml}
<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"2000\" width=\"2000\">";
echo $html;
echo $svgcode;
echo "</svg>";
} // end graphViz entity relationship diagram
else if ($yumlDiagram) {
$thedir = dirname($outputFilename);
exec("rm -rf " . $thedir . "/yuml.txt");
copy($thedir . "/model.ump.output", $thedir . "/yuml.txt");
$command = "python yuml.py -i " . $thedir . "/yuml.txt -o " . $thedir . "/yuml.png -s plain ";
$res = shell_exec($command . " 2>&1");
$yumllink = $workDir->makePermalink('yuml.txt');
$imglink = $workDir->makePermalink('yuml.png');
if (file_exists($thedir . "/yuml.png"))
{
$dltext = " <a href=\"$imglink\">Download the PNG file for the image</a> <br/>
<img src=\"$imglink\"\>";
}
else
{
// could not generate either because of Python problem
// or the yuml server not delivering because it doesn't like automated systems
$yumltxt = file_get_contents($thedir."/yuml.txt");
$dltext = " <a target=\"yumlimg\" href=\"http://yuml.me/diagram/plain/class/".urlencode($yumltxt).".php\"> Click on this link to display the png in a different Tab (yuml.me doesn't like automated systems generating their images)</a> ";
}
$html = "<a href=\"$yumllink\">Download the Yuml text for the yuml image</a>. You can then use this text to generate various image formats at <a target=\"yumlimg\" href=\"https://yuml.me/diagram/plain/class/draw\">yuml.me</a> <br/>$dltext";
echo $html;
} // end yuml diagram
else // This is where the Java, PHP and other output is placed on the screen
{
exec("cd $thedir; rm {$language}FromUmple.zip; zip -r {$language}FromUmple {$language}");
$archivelink = $workDir->makePermalink($language.'FromUmple.zip');
echo "<a href=\"$archivelink\" class=\"zipDownloadLink\">Download the following as a zip file</a> {$errhtml}<p>URL_SPLIT";
echo $sourceCode;
}
}
} // end not UIGU
else
{ // is UIGU
// variables here come from the uigu clause in the previous if statement
// for all relative paths we assume we are chdir'd into a specific directory by showUserInterface
$theurldir = $workDir->getPath();
$filename = $theurldir.'/'.$dataname;
$errorFilename = "{$filename}.erroroutput";
$errhtml = getErrorHtml($errorFilename);
$uiguDir=file_get_contents("uigudir.txt");
$uiguIframe = $workDir->makePermalink('');
$warlink = $workDir->makePermalink('umpleUIGU.war');
$html = "<a href=\"$warlink\">Download the generated application as web archive (WAR) file.</a> {$errhtml}
<iframe width=100% height=300 src='$uiguIframe/'></iframe>
";
echo $html;
}
} // end request has umpleCode
else if (isset($_REQUEST["exampleCode"]))
{
$filename = rootDir()."/ump/" . $_REQUEST["exampleCode"];
$outputUmple = readTemporaryFile($filename);
echo $outputUmple;
}
else if (isset($_REQUEST["asImage"]))
{
$asImage = $_REQUEST["asImage"];
$json = json_decode($asImage);
showUmlImage($json);
}
else if (isset($_REQUEST["asYuml"]))
{
showYumlImage($_REQUEST["asYuml"]);
}
else if (isset($_REQUEST["asUI"]))
{
showUserInterface($_REQUEST["asUI"]);
}
else
{
echo "Invalid use of compiler";
}
function getErrorHtml($errorFilename, $offset = 1)
{
$errorMessage = readTemporaryFile($errorFilename);
if($errorMessage != "")
{
savefile("",$errorFilename); // Clean error so it is gone for next time
$errInfo = jsonDecode($errorMessage);
$errhtml = "<a href='#' id='errorClick'>Show/Hide errors and warnings</a>";
$errhtml .= "<div id='errorRow' colspan='3' >"; // style='display:none'
if($errInfo == null)
{
$errhtml .= "Couldn't read results from the Umple compiler!<br><pre>".$errorMessage."</pre>";
}
else
{
$results = $errInfo["results"];
foreach($results as $result)
{
$url = $result["url"];
$line = intval($result["line"]) - $offset;
$errorCode = $result["errorCode"];
$severityInt = intval($result["severity"]);
if($severityInt > 2) {
$severity = "Warning";
$textcolor = "<font color=\"black\">";
}
else
{
$severity = "Error";
$textcolor = "<font color=\"red\">";
}
$msg = htmlspecialchars($result["message"]);
$errhtml .= $textcolor." {$severity} on <a href=\"javascript:Action.setCaretPosition({$line});Action.updateLineNumberDisplay();\">line {$line}</a> : {$msg}.</font> <i><a href=\"{$url}\" target=\"helppage\">More information ({$errorCode})</a></i></br>";
}
}
$errhtml .= "</div>";
$errhtml .= "<script type=\"text/javascript\">jQuery(\"#errorClick\").click(function(a){a.preventDefault();jQuery(\"#errorRow\").toggle();});</script>";
return $errhtml;
}
return "";
}
// taken from http://php.net/manual/en/function.json-decode.php
function jsonDecode ($json)
{
$json = str_replace(array("\\\\", "\\\""), array("\", """), $json);
$parts = preg_split("@(\"[^\"]*\")|([\[\]\{\},:])|\s@is", $json, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
foreach ($parts as $index => $part)
{
if (strlen($part) == 1)
{
switch ($part)
{
case "[":
case "{":
$parts[$index] = "array(";
break;
case "]":
case "}":
$parts[$index] = ")";
break;
case ":":
$parts[$index] = "=>";
break;
case ",":
break;
default:
return null;
}
}
else
{
if ((substr($part, 0, 1) != "\"") || (substr($part, -1, 1) != "\""))
{
return null;
}
}
}
$json = str_replace(array("\", """, "$"), array("\\\\", "\\\"", "\\$"), implode("", $parts));
return eval("return $json;");
}
?>