fix to display the four-panel link in the prescription list only when CAMOS is installed
[openemr.git] / library / registry.inc
blob037df0705093042752aa4dd3dfe21f5b7c1e811c
1 <?php
2 //these are the functions used to access the forms registry database
3 //
4 //include_once("../../globals.php");
5 include_once("{$GLOBALS['srcdir']}/sql.inc");
7 function registerForm ( $directory , $sql_run=0 , $unpackaged=1 , $state=0 )
9         $check = sqlQuery("select state from registry where directory='$directory'");
10         if ($check == false)
11         {
12                 $lines = @file($GLOBALS['srcdir']."/../interface/forms/$directory/info.txt");
13                 if ($lines)
14                         $name = $lines[0];
15                 else
16                         $name = $directory;
17                 return sqlInsert("insert into registry set
18                         name='$name',
19                         state='$state',
20                         directory='".mysql_escape_string($directory)."',
21                         sql_run='$sql_run',
22                         unpackaged='$unpackaged',
23                         date=NOW()
24                 ");
25         }
26         return false;
29 function updateRegistered ( $id, $mod )
31         return sqlInsert("update registry set
32                 $mod,
33                 date=NOW() 
34         where
35                 id='$id'
36         ");
39 function getRegistered ( $state="1", $limit="unlimited", $offset="0")
41         $sql = "select name, state, directory, id, sql_run, unpackaged, date from registry where state like \"$state\" order by name";
42         if ($limit != "unlimited")
43                 $sql .= " limit $limit, $offset";
44         $res = sqlStatement($sql);
45         if ($res)
46         for($iter=0; $row=sqlFetchArray($res); $iter++)
47         {
48                 $all[$iter] = $row;
49         }
50         else
51                 return false;
52         return $all;
55 function getRegistryEntry ( $id, $cols = "*" )
57         $sql = "select $cols from registry where id='$id'";
58         return sqlQuery($sql);
61 function installSQL ( $dir )
63         $sqltext = $dir."/table.sql";
64         if ($sqlarray = @file($sqltext))
65         {
66                 $sql = implode("", $sqlarray);
67                 //echo "<br>$sql<br><br>";
68                 $sqla = split(";",$sql);
69                 foreach ($sqla as $sqlq) {
70                   if (strlen($sqlq) > 5) {
71                    sqlStatement(rtrim("$sqlq"));
72                   }
73                 }
74                         
75                 return true;
76         }else
77                 return false;
81 /* 
82  * is a form registered
83  *  (optional - and active)
84  * in the database?
85  * 
86  *  INPUT =   id => form ID
87  *            state => 0=inactive / 1=active
88  *  OUTPUT = true or false
89  */
90 function isRegistered ( $id, $state = 1)
92     $sql = "select id from registry where ".
93             "id=".$id.
94             " and state=".$state;
95     $result = sqlQuery($sql);
96     if ($result['id'] != '') return true;
97     return false;
102  * given a form directory return the unique ID
103  * for the associated form
104  * NOTE - sometimes the Name of a form has a line-break at the end, thus this function might be better
105  */
106 function getIdByDirectory ( $directory )
108     $sql = "select id from registry where ".
109             " directory = '".$directory."'";
110     $result = sqlQuery($sql);
111     if ($result['id'] != '') return $result['id'];
112     return null;