PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/da_catalog_editDatasetRecord.php

https://github.com/jmjamison/da_catalog_maintenance
PHP | 475 lines | 253 code | 167 blank | 55 comment | 20 complexity | 54390ed41d1df4ad7fa713d68296889c MD5 | raw file
  1. <html>
  2. <head><title>Data Archive Catalog: Input Dataset Record</title>
  3. <link rel="stylesheet" href="2col_leftNav.css" type="text/css">
  4. </head>
  5. <body>
  6. <?php
  7. $sscnetHTTP = "http://www.sscnet.ucla.edu/issr/da/da_catalog/";
  8. $sscnetHTTP_maintenance_test = "http://www.sscnet.ucla.edu/issr/da/da_catalog_maintenance_test/";
  9. $sscnetHTTP_maintenance_live = "http://www.sscnet.ucla.edu/issr/da/da_catalog_maintenance/";
  10. $mydestopHTTP = "http://localhost/da_catalog/";
  11. $currentHTTP = $sscnetHTTP_maintenance_live;
  12. $sscnetInclude = "ISSRDA_login.php";
  13. $currentInclude = $sscnetInclude;
  14. include($currentInclude);
  15. // for desktop test system
  16. //$db_name = "da_catalog";
  17. if (!empty($_POST['studynumber'])) {
  18. //echo "studynumber: " . $studynumber;
  19. $_SESSION['studynumber'] = $_POST['studynumber'];
  20. // something is selected
  21. //$queryDatasetRecord="SELECT wwwlink.wwwlink, wwwlink.wwwtext, wwwlink.WWWcode, wwwlink.studynum, fileinfo.*, fileinfo.Restricted AS restricted_file, fileinfo.StudyNum, fileinfo.ID as datasetID, data_cite.ID as citeID FROM cite AS data_cite RIGHT JOIN (wwwlink RIGHT JOIN fileinfo ON wwwlink.dtafile = fileinfo.DTAfile) ON data_cite.citenum = fileinfo.Cite WHERE fileinfo.StudyNum='" . $studynumber . "'";
  22. //$queryDatasetRecord="SELECT wwwlink.*, fileinfo.*, fileinfo.Restricted AS restricted_file, fileinfo.StudyNum, fileinfo.ID as datasetID, cite.citenum, cite.ID as citeID, cite.cite as cite_text, cite.subsort as cite_subsort FROM cite RIGHT JOIN (wwwlink RIGHT JOIN fileinfo ON wwwlink.dtafile = fileinfo.DTAfile) ON cite.citenum = fileinfo.Cite WHERE fileinfo.StudyNum='" . $studynumber . "'";
  23. //$queryDatasetRecord="SELECT wwwlink.wwwlink, wwwlink.wwwtext, wwwlink.WWWcode, wwwlink.studynum, fileinfo.*, data_cite.cite AS cite, fileinfo.Restricted AS restricted_file, fileinfo.StudyNum, fileinfo.ID as datasetID, data_cite.ID as citeID, data_cite.citenum, data_cite.cite as cite_text, data_cite.subsort as cite_subsort FROM cite AS data_cite RIGHT JOIN (wwwlink RIGHT JOIN fileinfo ON wwwlink.dtafile = fileinfo.DTAfile) ON data_cite.citenum = fileinfo.Cite WHERE (fileinfo.StudyNum='" . $studynumber . "')";
  24. // this pulls in EVERYTHING - espectially everything where fileinfo.DTAfile=wwwlink.dtafile is blank -- has to be cleaned out after the select
  25. // add test for DTAfile blank - and fileinfo.DTAfile <> "";
  26. $queryDatasetRecord="SELECT fileinfo.*, fileinfo.Restricted AS restricted_file, fileinfo.ID as datasetID, cite.ID as citeID, cite.citenum, cite.cite as cite_text, cite.subsort as cite_subsort, wwwlink.wwwlink, wwwlink.wwwtext, wwwlink.WWWcode, wwwlink.dtafile FROM (fileinfo LEFT JOIN cite on fileinfo.Cite = cite.citenum) LEFT JOIN wwwlink on fileinfo.DTAfile = wwwlink.dtafile WHERE fileinfo.StudyNum='" . $studynumber . "' and fileinfo.DTAfile <> ''";
  27. //$queryDatasetRecord="SELECT fileinfo.*, fileinfo.Restricted AS restricted_file, fileinfo.StudyNum, wwwlink.*, cite.* FROM (fileinfo LEFT JOIN wwwlink ON fileinfo.DTAfile = wwwlink.dtafile) INNER JOIN cite ON fileinfo.Cite = cite.citenum WHERE (fileinfo.StudyNum='" . $studynumber . "')";
  28. echo "<strong>dataset record query:</strong> " . $queryDatasetRecord . "<strong>;</strong> ";
  29. // PDO connect
  30. $PDO_string = "mysql:host=" . $db_host . ";port=" . $db_port . ";dbname=" . $db_name ;
  31. // echo "<br>" . $queryGetBaseRecord . "<br>";
  32. try {
  33. $PDO_connection = new PDO($PDO_string, $db_username, $db_password);
  34. } catch(PDOException $e) {
  35. echo "Could not connect to the database because: ". $e->getMessage()."<br>";
  36. die();
  37. }
  38. // --------------------------------------------------------
  39. $PDO_query = $PDO_connection->prepare($queryDatasetRecord);
  40. // PDO - execute the query
  41. $result = $PDO_query->execute();
  42. if (!$result) {
  43. die ("Could not query the database: <br />". mysql_error());
  44. }
  45. // complete record info
  46. $datasetRecord = array(); // record - the title, sub# and restricted y/n
  47. $row_index = 0;
  48. while ($row = $PDO_query->fetch(PDO::FETCH_ASSOC)) {
  49. // alraedy have the sturynumber - $studynumber
  50. $datasetRecord[$row_index]["datasetID"] = $row["datasetID"]; // id for dataset record
  51. $datasetRecord[$row_index]["dataset_studypart"] = $row["StudyPart"]; // id for dataset record
  52. $datasetRecord[$row_index]["dtafile"] = $row["DTAfile"];
  53. $datasetRecord[$row_index]["dsname"] = $row["Dsname"];
  54. $datasetRecord[$row_index]["citenum"] = $row["Cite"];
  55. $datasetRecord[$row_index]["alttype"] = $row["AltType"];
  56. $datasetRecord[$row_index]["altsnum"] = $row["AltSNUM"];
  57. $datasetRecord[$row_index]["filetype"] = $row["FileType"];
  58. $datasetRecord[$row_index]["note"] = $row["Note"];
  59. $datasetRecord[$row_index]["dsname"] = $row["Dsname"];
  60. $datasetRecord[$row_index]["fullsize"] = $row["Fullsize"]; // NOTE: legacy - use Fullsize (vs. Gzipsize) for filesize
  61. //-------------------------------------------------------------------------------
  62. $datasetRecord[$row_index]["wwwID"] = $row["WWWcode"]; // id for dataset record
  63. $datasetRecord[$row_index]["wwwtext"] = $row["wwwtext"];
  64. $datasetRecord[$row_index]["wwwlink"] = $row["wwwlink"];
  65. //-------------------------------------------------------------------------------
  66. $datasetRecord[$row_index]["citeID"] = $row["citeID"]; // id for dataset record
  67. $datasetRecord[$row_index]["cite_text"] = $row["cite_text"];
  68. $datasetRecord[$row_index]["cite_subsort"] = $row["cite_subsort"];
  69. $datasetRecord[$row_index]["citenum"] = $row["citenum"]; // <-- the connecting field: cite.citenum to fileinfo.Cite
  70. $row_index++;
  71. }
  72. }
  73. //print_r($datasetRecord);
  74. $datasetRecordListCount = count($datasetRecord);
  75. echo "<br><strong>Studynumber:</strong> " . $studynumber . "; <strong> Dataset record count:</trong> " . $datasetRecordListCount . "<br>";
  76. $queryTitleStudyNumFileType = "SELECT title.StudyNum, fileinfo.FileType, fileinfo.dtafile, fileinfo.dtafilename as datasetID FROM title LEFT JOIN fileinfo ON title.StudyNum = fileinfo.StudyNum ORDER BY title.StudyNum";
  77. // PDO connect
  78. $PDO_string = "mysql:host=" . $db_host . ";port=" . $db_port . ";dbname=" . $db_name ;
  79. try {
  80. $PDO_connection = new PDO($PDO_string, $db_username, $db_password);
  81. } catch(PDOException $e) {
  82. echo "Could not connect to the database because: ". $e->getMessage()."<br>";
  83. die();
  84. }
  85. // PDO - create prepared statement: get the table.pifull
  86. // --------------------------------------------------------
  87. $PDO_query = $PDO_connection->prepare($queryTitleStudyNumFileType);
  88. // PDO - execute the query
  89. $result = $PDO_query->execute();
  90. if (!$result) {
  91. die ("Could not query the database: <br />". mysql_error());
  92. }
  93. $fileTypeList = array();
  94. $studynumberList = array();
  95. $titleList = array();
  96. $dtafileList = array();
  97. $result = $PDO_query->fetch(PDO::FETCH_ASSOC);
  98. $row_index = 0;
  99. while ($row = $PDO_query->fetch(PDO::FETCH_ASSOC)) {
  100. $studynumberList[$row_index] = $row["StudyNum"];
  101. if (!is_null($row["FileType"])) { $fileTypeList[$row_index] = $row["FileType"]; } // others won't have nulls
  102. $dtafileList[$row_index] = $row["dtafile"];
  103. $row_index++;
  104. }
  105. $fileTypeList = array_unique($fileTypeList);
  106. sort($fileTypeList);
  107. $fileTypeTotal = count($fileTypeList);
  108. $dtafileList = array_unique($dtafileList);
  109. sort($dtafileList);
  110. $studynumberList = array_unique($studynumberList);
  111. sort($studynumberList);
  112. $studynumberListTotal = count($studynumberList);
  113. $fileTypeListText = implode("','", $fileTypeList);
  114. $fileTypeListText = "'" . $fileTypeListText . "'";
  115. ?>
  116. <script type="text/javascript">
  117. var counter = 0;
  118. function addNewFileTypeEntry(arg1, arg2) {
  119. // element containing the new file type entry
  120. var currentEntryID = arg1;
  121. alert(currentEntryID);
  122. var currentEntryName = document.getElementById(currentEntryID).name;
  123. alert("new entry form name: " + currentEntryID);
  124. var newText = document.getElementById(currentEntryID).value;
  125. alert("Add this file type: " + newText);
  126. // element containt the old file type list
  127. var oldSelectBoxID = arg2;
  128. alert(oldSelectBoxID);
  129. var oldSelectBoxName = document.getElementById(oldSelectBoxID).name;
  130. alert("old select box name: " + oldSelectBoxName);
  131. var fileTypeList = new Array(<?php echo $fileTypeListText; ?>);
  132. var fileListTotal = fileTypeList.length;
  133. alert("Current total items: " + fileListTotal);
  134. document.getElementById(oldSelectBoxID).innerHTML = "";
  135. // write in the new, added file type first, the re-add the original filetype list
  136. var newOption = document.createElement("option");
  137. newOption.value = newText;
  138. newOption.text = newText;
  139. document.getElementById(oldSelectBoxID).appendChild(newOption);
  140. for (i = 0; i < fileListTotal; i++) {
  141. var newOption = document.createElement("option");
  142. newOption.value = fileTypeList[i];
  143. newOption.text = fileTypeList[i];
  144. document.getElementById(oldSelectBoxID).appendChild(newOption);
  145. } // end of for-loop rewrite the option list
  146. } // end addNewFileType
  147. </script>
  148. <div id="masthead"><!--begin masthead-->
  149. <h1 id="siteName">UCLA Institute for Social Research Data Archives</h1>
  150. <h2 id="siteName"><a href="index.php" target="_self">Maintenance Menu</a>&nbsp;/&nbsp;Edit Dataset Record(s)</h2>
  151. </div> <!--end masthead--><!--end masthead-->
  152. <div style="margin: 1% 5% 2% 2%;line-height: 1.5; ">
  153. <form <?php
  154. if (isset($_SESSION['studynumber'])) { // a study has been chose so post means go to updateCheck
  155. echo " action='da_catalog_updateDatasetRecordCheck.php'";
  156. } else { // a study HAS NOT been chosen so post the study info back to the input page when you do choose a study
  157. echo " action=''";
  158. }
  159. ?> method="post" name="updateRecord" target="_self">
  160. <p><label>Studynumber:
  161. <?php
  162. if (isset($_SESSION['studynumber'])) {
  163. $studynumber = $_SESSION['studynumber'];
  164. echo '<input name="studynumber" type="text" id="studynumber" value="' . $studynumber . '" size="30" maxlength="255">';
  165. echo '</select>';
  166. } else {
  167. echo '<select name="studynumber" id="studynumber">';
  168. echo '<option value="">choose studynumber</option>';
  169. foreach ($studynumberList as $key => $value) {
  170. echo '<option value="' . $value . '">' . $value;
  171. }
  172. echo " <input name='getbaserecord' type='submit' id='getbaserecord' value='Get this Studynumber'>";
  173. }
  174. $studynumArray = explode("V",$studynumber);
  175. $studyNumShort = $studynumArray[0];
  176. ?></label>
  177. <!--<input name="updateTitle" type="submit" id="updateTitle" value="save/update record">
  178. <input name="reset form" type="reset" value="reset">
  179. <input type="button" onClick="history.go(0)" value="Reload page">-->
  180. <br>
  181. <hr align="center" width="100%" size="1">
  182. <?php
  183. // test to see if there are ANY records attached
  184. // if-no - informational message
  185. // else-yes - display them
  186. if (($datasetRecordListCount <= 0) AND (isset($studynumber))) {
  187. echo "There are no records attached to Study# " . $studynumber . ".";
  188. } else {
  189. $previousDatasetID = null;
  190. $blue = "#CCFFFF";
  191. $yellow = "#FFFFCC";
  192. $color = $blue;
  193. //echo "Starting color: " . $color . "<br>";
  194. for ($row_index = 0; $row_index < $datasetRecordListCount; $row_index++) { // start of for-loop dataset list
  195. // alraedy have the sturynumber - $studynumber
  196. $datasetID = $datasetRecord[$row_index]["datasetID"]; // id for dataset record
  197. $dataset_studypart = $datasetRecord[$row_index]["dataset_studypart"];
  198. $dtafile = $datasetRecord[$row_index]["dtafile"];
  199. $dsname = $datasetRecord[$row_index]["dsname"];
  200. //$studyNumShort = $datasetRecord[$row_index]["studyNumShort"];
  201. $alttype = $datasetRecord[$row_index]["alttype"];
  202. $altsnum = $datasetRecord[$row_index]["altsnum"];
  203. $filetype = $datasetRecord[$row_index]["filetype"];
  204. $note = $datasetRecord[$row_index]["note"];
  205. $dsname = $datasetRecord[$row_index]["dsname"];
  206. $filesize = $datasetRecord[$row_index]["fullsize"]; // NOTE: legacy - use Fullsize (vs. Gzipsize) for filesize
  207. //-------------------------------------------------------------------------------
  208. $wwwID = $datasetRecord[$row_index]["wwwID"]; // id for dataset record
  209. $wwwtext = $datasetRecord[$row_index]["wwwtext"];
  210. $wwwlink = $datasetRecord[$row_index]["wwwlink"];
  211. //-------------------------------------------------------------------------------
  212. $citeID = $datasetRecord[$row_index]["citeID"]; // id for dataset record
  213. $cite_text = $datasetRecord[$row_index]["cite_text"];
  214. $cite_subsort = $datasetRecord[$row_index]["cite_subsort"];
  215. $citenum = $datasetRecord[$row_index]["citenum"]; // <-- the connecting field: cite.citenum to fileinfo.Cite
  216. //-----------------------------------------------------
  217. // beginning of item record
  218. //-----------------------------------------------------
  219. if ($datasetID != $previousDatasetID) { // first: check for dups
  220. echo "<div id='dynamicInput'><p>"; // first div encompases the dataset record AREA, the 2nd is the individual record
  221. // NOTE: the studypart variable is used to sort the various datasets in order, so start with #1
  222. //echo " </p>";
  223. //echo "<div id='datasetrecord' style='background-color: " . $color . "'><br>";
  224. echo "<div id='datasetrecord' style='background-color: " . $color . "'>"; // div #2 for record area
  225. echo "<form action='da_catalog_updateDatasetRecordCheck.php' method='post' name='updateDatasetRecord'><br>";
  226. if ($color == $blue) {
  227. $color = $yellow;
  228. } elseif ($color == $yellow) {
  229. $color = $blue;
  230. }
  231. echo "<input name='studynumber' type='hidden' value='" . $studynumber . "'>";
  232. echo "<label>dataset ID: " . $datasetID . "</label> and <label>Dtafile number : " . $dtafile . "</label> ";
  233. echo "<hr align='center' width='100%' size='1'>";
  234. //<!--<input name='dtafile' type='text' size='20' value=" . $dtafile . "><br> -->";
  235. echo "Studypart number: <input name='studypart' type='text' size='3' value='" . $dataset_studypart . "' /> <input name='datasetID' type='hidden' value='" . $datasetID . "'>";
  236. echo " dataset name: <input name='dsname' type='text' value='" . $dsname . "'><br>";
  237. //echo "<br>filetype: <input name='filetype' type='text' value='" . $filetype . "'> Filetype:&nbsp;";
  238. echo "current filetype: " . $filetype . " ";
  239. echo "<select name='filetype' id='dropdownList" . $datasetID . "'>"; // use the datasetID to distinguish between each datasets filetype dropdown box
  240. echo '<option value="' . $filetype . '">' . $filetype;
  241. foreach ($fileTypeList as $key => $value) {
  242. echo '<option value="' . $value . '">' . $value;
  243. }
  244. ?>
  245. </select>
  246. <label>add a file type NOT LISTED: <input name='newfiletype' type='text' id="newFileTypeEntry<?php echo $datasetID; ?>"></label>
  247. <!--// use the datasetID to distinguish between each datasets filetype dropdown box -->
  248. <input name="da_catalog_insertSubjectCheck.php" type="button" onClick="addNewFileTypeEntry('newFileTypeEntry<?php echo $datasetID; ?>', 'dropdownList<?php echo $datasetID; ?>')" value="Add New File Type">
  249. <br>
  250. file size:<input type="text" name="filesize" id="filesize" value="<?php echo $filesize; ?>">
  251. <?php // NOTE: DTAfile number is a legacy variable, originally based on a combination of tape# + file#,
  252. // later it was generated as 999 + nnnn, just add 1 to the last number generated. 14.Oct.2009 jmj
  253. // This creates an incremented DTAfile number.
  254. //$foo = end($dtafileList);
  255. // $datfilePieces = explode("file", $foo);
  256. //echo " " . end($datfilePieces);
  257. // used below in the dtafile_new field
  258. //$endpart = end($datfilePieces);
  259. // echo "DTA999.file" . ($endpart + 1);
  260. ?>
  261. note: <input name="note" type="text" size="100" id="note" value="<?php echo $note; ?>">
  262. <hr align='center' width='100%' size='1'>
  263. wwwlink description: <input name="wwwtext" type="text" size="50" maxlength="255" value="<?php echo $wwwtext; ?>">
  264. wwwlink: http://<input name="wwwlink" type="text" size="50" maxlength="255" value="<?php echo $wwwlink; ?>"> WWWcode: <?php echo $wwwID; ?><br>
  265. <input name="wwwID" type="hidden" value="<?php echo $wwwID; ?>">
  266. Title link from other source, example - 'Roper': <input type="text" name="alttype" value="">
  267. Alternate studynumber from other source: <input name="altsnum" type="text" value="">
  268. <input type="hidden" name="studyNumShort" value="<?php echo $studyNumShort; ?>">
  269. <input type="hidden" name="dtafile" value="<?php echo $dtafile; ?>">
  270. <input type="hidden" name="gzsize" value="">
  271. <hr align='center' width='100%' size='1'>
  272. file level citation: <!--<input type="text" name="cite_text" size="200" maxlength="500" value=""> -->
  273. <textarea name="cite_text" cols="101" rows="4"><?php echo $cite_text; ?></textarea> citeID: <?php echo $citeID; ?>, subsort: <?php echo $cite_subsort; ?>, citenum: <?php echo $citenum; ?>
  274. <input name="citeID" type="hidden" value="<?php echo $citeID; ?>">
  275. <input name="cite_subsort" type="hidden" value="<?php echo $cite_subsort; ?>">
  276. <input name="citenum" type="hidden" value="<?php echo $citenum; ?>">
  277. <hr align='center' width='100%' size='1'>
  278. <input name="reset form" type="reset" value="reset">
  279. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  280. <input type="button" onClick="history.go(0)" value="Reload page">
  281. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  282. <input type="submit" name="updatedataset" id="updatedataset" value="Update this Dataset">
  283. </p>
  284. </form>
  285. </div> <!--End of Record Area -->
  286. <?php
  287. //-----------------------------------------------------
  288. // end of item record
  289. //-----------------------------------------------------
  290. ?>
  291. <p> <hr align="center" width="100%" size="1">
  292. <?php
  293. $previousDatasetID = $datasetID;
  294. } // end of the for-loop dataset list
  295. } // end of the for-loop for dtafile dups
  296. } // end of the if-else loop that tests to see if ANY datasets are attached
  297. ?>
  298. </p>
  299. </p>
  300. <p>&nbsp; </p>
  301. </div>
  302. <?php
  303. // close the connection
  304. // mysql_close($connection);
  305. $PDO_connection = null;
  306. ?>
  307. </div> <!-- end content-->
  308. </body></html>