PageRenderTime 24ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/lib/resources.inc

https://bitbucket.org/rbonesource1234/no2co2
PHP | 370 lines | 297 code | 64 blank | 9 comment | 41 complexity | 5010a027a41376f649ac3a755921efb5 MD5 | raw file
  1. <?php
  2. include_once($_SERVER['ROOT_DIR'].'conf/global.inc');
  3. class ResourceAdmin{
  4. function ResourceAdmin(){
  5. }
  6. function getKeyword() {
  7. global $dblink;
  8. $arycategory = array();
  9. $sql= 'SELECT * FROM keyword';
  10. $rs = mysql_query($sql,$dblink);
  11. $i =1;
  12. if($rs && mysql_num_rows($rs) > 0) {
  13. $arykeyword[0] = array('id'=>'null', 'value'=>'--- Select ---');
  14. while($ary = mysql_fetch_assoc($rs)){
  15. $arykeyword[$i]['id'] = $ary['KeywordId'];
  16. $arykeyword[$i]['value'] = $ary['KeywordText'];
  17. $i++;
  18. }
  19. return $arykeyword;
  20. }
  21. }
  22. function getResource() {
  23. global $dblink;
  24. $arycategory = array();
  25. $sql= 'SELECT * FROM resources';
  26. $rs = mysql_query($sql,$dblink);
  27. $i =1;
  28. if($rs && mysql_num_rows($rs) > 0) {
  29. $aryresources[0] = array('id'=>'null', 'value'=>'--- Select ---');
  30. while($ary = mysql_fetch_assoc($rs)){
  31. $aryresources[$i]['id'] = $ary['ResourceId'];
  32. $aryresources[$i]['value'] = $ary['CompanyName'];
  33. $i++;
  34. }
  35. return $aryresources;
  36. }
  37. }
  38. function getResourceCity(){
  39. global $dblink;
  40. $arycategory = array();
  41. $sql = 'SELECT * FROM resourcecity Order by CityName';
  42. $rs = mysql_query($sql,$dblink);
  43. $i =1;
  44. if($rs && mysql_num_rows($rs) > 0) {
  45. while($ary = mysql_fetch_assoc($rs)){
  46. $ArySend[$i]['id'] = $ary['CityName'];
  47. $ArySend[$i]['value'] = $ary['CityName'];
  48. $i++;
  49. }
  50. $ArySend[0] = array('id'=>'null', 'value'=>'--- Select ---');
  51. return $ArySend;
  52. }
  53. }
  54. function ListResources(){
  55. global $dblink;
  56. $sql= 'SELECT * FROM resources r , resourcesinfo r1 , keyword k Where r.ResourceId = r1.ResourceId And r1.KeywordId = k.KeywordId ORDER BY r.ResourceId desc';
  57. $rs = mysql_query($sql, $dblink);
  58. if (($rs) && (mysql_num_rows($rs))) {
  59. $j=0;
  60. while($ary = mysql_fetch_assoc($rs)) {
  61. $ArylListResources[$j] = $ary;
  62. $j++;
  63. }
  64. } else {
  65. $ArylListResources = array();
  66. }
  67. return $ArylListResources;
  68. }
  69. function SaveResources(){
  70. global $dblink;
  71. $target = "../resourceupload/";
  72. foreach ($_POST as $key => $value) {
  73. $InsertAry[$key] = StrAddSlashes($value);
  74. }
  75. $target1 = $target . basename($_FILES['fileaddt1']['name']) ;
  76. if(move_uploaded_file($_FILES['fileaddt1']['tmp_name'], $target1)){
  77. $message1= "The file ". basename( $_FILES['fileaddt1']['name']). " has been uploaded";
  78. } else $mesg = 'Error1';
  79. $target2 = $target . basename($_FILES['fileaddt2']['name']) ;
  80. if(move_uploaded_file($_FILES['fileaddt2']['tmp_name'], $target2)){
  81. $message1= "The file ". basename( $_FILES['fileaddt2']['name']). " has been uploaded";
  82. } else $mesg = 'Error2';
  83. $target3 = $target . basename($_FILES['fileaddt3']['name']) ;
  84. if(move_uploaded_file($_FILES['fileaddt3']['tmp_name'], $target3)){
  85. $message1= "The file ". basename( $_FILES['fileaddt3']['name']). " has been uploaded";
  86. } else $mesg = 'Error3';
  87. $target4 = $target . basename($_FILES['fileaddt4']['name']) ;
  88. if(move_uploaded_file($_FILES['fileaddt4']['tmp_name'], $target4)){
  89. $message1= "The file ". basename( $_FILES['fileaddt4']['name']). " has been uploaded";
  90. } else $mesg = 'Error4';
  91. $sql ='INSERT INTO resources(CompanyName, ContactPerson1,ContactPerson2,ContactPerson3,ContactPerson4,
  92. Address1,Address2,Address3,Address4,
  93. City,CompanyAddress, OfficialEmail, TelephoneNo,
  94. Telephone1,Telephone2,Telephone3 ,Telephone4,
  95. MobileNo1,MobileNo2,MobileNo3,MobileNo4,
  96. EmailId1,EmailId2,EmailId3,EmailId4 ,
  97. Url1,Url2,Url3,Url4,
  98. UrlDescriptor1,UrlDescriptor2,UrlDescriptor3,UrlDescriptor4,
  99. TeamComment,ExpertComment,
  100. FileInfo1,FileInfo2,FileInfo3,FileInfo4,
  101. DownloadPath1,DownloadPath2,DownloadPath3,DownloadPath4,
  102. FileDescriptor1,FileDescriptor2,FileDescriptor3,FileDescriptor4,
  103. TimeInfo) VALUES (
  104. \''.$InsertAry['resourceName'].'\',
  105. \''.$InsertAry['resourceContactPersonP1'].'\',
  106. \''.$InsertAry['resourceContactPersonP2'].'\',
  107. \''.$InsertAry['resourceContactPersonP3'].'\',
  108. \''.$InsertAry['resourceContactPersonP4'].'\',
  109. \''.$InsertAry['addt1'].'\',
  110. \''.$InsertAry['addt2'].'\',
  111. \''.$InsertAry['addt3'].'\',
  112. \''.$InsertAry['addt4'].'\',
  113. \''.$InsertAry['resourceCity'].'\',
  114. \''.$InsertAry['companyadd'].'\',
  115. \''.$InsertAry['officialemail'].'\',
  116. \''.$InsertAry['telephoneno'].'\',
  117. \''.$InsertAry['telp1'].'\',
  118. \''.$InsertAry['telp2'].'\',
  119. \''.$InsertAry['telp3'].'\',
  120. \''.$InsertAry['telp4'].'\',
  121. \''.$InsertAry['MobM1'].'\',
  122. \''.$InsertAry['MobM2'].'\',
  123. \''.$InsertAry['MobM3'].'\',
  124. \''.$InsertAry['MobM4'].'\',
  125. \''.$InsertAry['emailt1'].'\',
  126. \''.$InsertAry['emailt2'].'\',
  127. \''.$InsertAry['emailt3'].'\',
  128. \''.$InsertAry['emailt4'].'\',
  129. \''.$InsertAry['Urladdt1'].'\',
  130. \''.$InsertAry['Urladdt2'].'\',
  131. \''.$InsertAry['Urladdt3'].'\',
  132. \''.$InsertAry['Urladdt4'].'\',
  133. \''.$InsertAry['Urldesc1'].'\',
  134. \''.$InsertAry['Urldesc2'].'\',
  135. \''.$InsertAry['Urldesc3'].'\',
  136. \''.$InsertAry['Urldesc4'].'\',
  137. \''.$InsertAry['no2co2Comment'].'\',
  138. \''.$InsertAry['ExpertComment'].'\',
  139. \''.basename($_FILES['fileaddt1']['name']).'\',
  140. \''.basename($_FILES['fileaddt2']['name']).'\',
  141. \''.basename($_FILES['fileaddt3']['name']).'\',
  142. \''.basename($_FILES['fileaddt4']['name']).'\',
  143. \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt1']['name']).'\',
  144. \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt2']['name']).'\',
  145. \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt3']['name']).'\',
  146. \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt4']['name']).'\',
  147. \''.$InsertAry['UploadDescriptor1'].'\',
  148. \''.$InsertAry['UploadDescriptor2'].'\',
  149. \''.$InsertAry['UploadDescriptor3'].'\',
  150. \''.$InsertAry['UploadDescriptor4'].'\',
  151. now())';
  152. $rs = mysql_query($sql, $dblink);
  153. $resourceid = mysql_insert_id();
  154. if ($rs && $resourceid) {
  155. $sql1 = 'INSERT INTO resourcesinfo(ResourceId, KeyWordId) VALUES(\''.$resourceid.'\',\''.$_POST['Keyword'].'\')';
  156. $rs2 = mysql_query($sql1, $dblink);
  157. if($rs2) {
  158. header('Location: ReDirect.php?action=Tier5');
  159. }
  160. } else {
  161. return 'false';
  162. }
  163. }
  164. function delresource(){
  165. global $dblink;
  166. $resourceid= base64_decode($_REQUEST['resourceid']);
  167. $sql='DELETE FROM resources WHERE ResourceId=\''.$resourceid.'\'';
  168. $result = mysql_query($sql, $dblink);
  169. $sql1='DELETE FROM resourcesinfo WHERE ResourceId = \''.$resourceid.'\'';
  170. $result1 = mysql_query($sql1, $dblink);
  171. if($result)
  172. return 'true';
  173. else return 'false';
  174. }
  175. function FetchResource($resid) {
  176. global $dblink;
  177. $sql = "SELECT * FROM resources Where ResourceId = '".$resid."' ";
  178. $result = mysql_query($sql,$dblink);
  179. if($result && mysql_num_rows($result) > 0){
  180. while($ary = mysql_fetch_assoc($result)){
  181. $araytier5 = $ary;
  182. }
  183. }
  184. return $araytier5;
  185. }
  186. function EditResources() {
  187. global $dblink;
  188. $target = "../resourceupload/";
  189. foreach ($_POST as $key => $value) {
  190. $InsertAry[$key] = StrAddSlashes($value);
  191. }
  192. $target1 = $target . basename($_FILES['fileaddt1']['name']) ;
  193. if(move_uploaded_file($_FILES['fileaddt1']['tmp_name'], $target1)){
  194. $message1= "The file ". basename( $_FILES['fileaddt1']['name']). " has been uploaded";
  195. } else $mesg = 'Error1';
  196. $target2 = $target . basename($_FILES['fileaddt2']['name']) ;
  197. if(move_uploaded_file($_FILES['fileaddt2']['tmp_name'], $target2)){
  198. $message1= "The file ". basename( $_FILES['fileaddt2']['name']). " has been uploaded";
  199. } else $mesg = 'Error2';
  200. $target3 = $target . basename($_FILES['fileaddt3']['name']) ;
  201. if(move_uploaded_file($_FILES['fileaddt3']['tmp_name'], $target3)){
  202. $message1= "The file ". basename( $_FILES['fileaddt3']['name']). " has been uploaded";
  203. } else $mesg = 'Error3';
  204. $target4 = $target . basename($_FILES['fileaddt4']['name']) ;
  205. if(move_uploaded_file($_FILES['fileaddt4']['tmp_name'], $target4)){
  206. $message1= "The file ". basename( $_FILES['fileaddt4']['name']). " has been uploaded";
  207. } else $mesg = 'Error4';
  208. $sql ='Update resources Set CompanyName = \''.$InsertAry['resourceName'].'\',
  209. ContactPerson1 = \''.$InsertAry['resourceContactPersonP1'].'\',
  210. ContactPerson2 = \''.$InsertAry['resourceContactPersonP2'].'\',
  211. ContactPerson3 = \''.$InsertAry['resourceContactPersonP3'].'\',
  212. ContactPerson4 = \''.$InsertAry['resourceContactPersonP4'].'\',
  213. Address1 = \''.$InsertAry['addt1'].'\',
  214. Address2 = \''.$InsertAry['addt2'].'\',
  215. Address3 = \''.$InsertAry['addt3'].'\',
  216. Address4 = \''.$InsertAry['addt4'].'\',
  217. City = \''.$InsertAry['resourceCity'].'\',
  218. CompanyAddress = \''.$InsertAry['companyadd'].'\',
  219. OfficialEmail = \''.$InsertAry['officialemail'].'\',
  220. TelephoneNo = \''.$InsertAry['telephoneno'].'\',
  221. Telephone1 = \''.$InsertAry['telp1'].'\',
  222. Telephone2 = \''.$InsertAry['telp2'].'\',
  223. Telephone3 = \''.$InsertAry['telp3'].'\',
  224. Telephone4 = \''.$InsertAry['telp4'].'\',
  225. MobileNo1 = \''.$InsertAry['MobM1'].'\',
  226. MobileNo2 = \''.$InsertAry['MobM2'].'\',
  227. MobileNo3 = \''.$InsertAry['MobM3'].'\',
  228. MobileNo4 = \''.$InsertAry['MobM4'].'\',
  229. EmailId1 = \''.$InsertAry['emailt1'].'\',
  230. EmailId2 = \''.$InsertAry['emailt2'].'\',
  231. EmailId3 = \''.$InsertAry['emailt3'].'\',
  232. EmailId4 = \''.$InsertAry['emailt4'].'\',
  233. Url1 = \''.$InsertAry['Urladdt1'].'\',
  234. Url2 = \''.$InsertAry['Urladdt2'].'\',
  235. Url3 = \''.$InsertAry['Urladdt3'].'\',
  236. Url4 = \''.$InsertAry['Urladdt4'].'\',
  237. UrlDescriptor1 = \''.$InsertAry['Urldesc1'].'\',
  238. UrlDescriptor2 = \''.$InsertAry['Urldesc2'].'\',
  239. UrlDescriptor3 = \''.$InsertAry['Urldesc3'].'\',
  240. UrlDescriptor4 = \''.$InsertAry['Urldesc4'].'\',
  241. TeamComment = \''.$InsertAry['no2co2Comment'].'\',
  242. ExpertComment = \''.$InsertAry['ExpertComment'].'\', ';
  243. if($_FILES['fileaddt1']['name']!='') {
  244. $sql .= 'FileInfo1 = \''.basename($_FILES['fileaddt1']['name']).'\',
  245. DownloadPath1 = \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt1']['name']).'\',
  246. FileDescriptor1 = \''.$InsertAry['UploadDescriptor1'].'\', ';
  247. }
  248. if($_FILES['fileaddt2']['name']!='') {
  249. $sql .= 'FileInfo2 = \''.basename($_FILES['fileaddt2']['name']).'\',
  250. DownloadPath2 = \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt2']['name']).'\',
  251. FileDescriptor2 = \''.$InsertAry['UploadDescriptor2'].'\', ';
  252. }
  253. if($_FILES['fileaddt3']['name']!='') {
  254. $sql .= 'FileInfo3 = \''.basename($_FILES['fileaddt3']['name']).'\',
  255. DownloadPath3 = \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt3']['name']).'\',
  256. FileDescriptor3 = \''.$InsertAry['UploadDescriptor3'].'\', ';
  257. }
  258. if($_FILES['fileaddt4']['name']!='') {
  259. $sql .= 'FileInfo4 = \''.basename($_FILES['fileaddt4']['name']).'\',
  260. DownloadPath4 = \''.RootUrl.'resourceupload/'.basename($_FILES['fileaddt4']['name']).'\',
  261. FileDescriptor4 = \''.$InsertAry['UploadDescriptor4'].'\', ';
  262. }
  263. $sql .= 'TimeInfo = now()
  264. Where ResourceId = \''.$InsertAry['ResourceID'].'\' ';
  265. $rs = mysql_query($sql, $dblink);
  266. $resourceid = mysql_insert_id();
  267. header('Location: ReDirect.php?action=Tier5');
  268. /*if ($rs && $resourceid) {
  269. $sql1 = 'Update resourcesinfo SET KeyWordId = \''.$_POST['Keyword'].'\'';
  270. $rs2 = mysql_query($sql1, $dblink);
  271. if($rs2) {
  272. header('Location: ReDirect.php?action=Tier5');
  273. }
  274. } else {
  275. return 'false';
  276. }*/
  277. }
  278. function DeleteFile($id, $resid) {
  279. global $dblink;
  280. if($id==1) {
  281. $sql = "Update resources Set FileInfo1= '', DownloadPath1= '', FileDescriptor1= '' Where ResourceId = '".$resid."' ";
  282. $result = mysql_query($sql,$dblink);
  283. $tier5id = base64_encode($resid);
  284. header("Location:editTier5.php?Tier5ID=$tier5id");
  285. }
  286. if($id==2) {
  287. $sql = "Update resources Set FileInfo2= '', DownloadPath2= '', FileDescriptor2= '' Where ResourceId = '".$resid."' ";
  288. $result = mysql_query($sql,$dblink);
  289. $tier5id = base64_encode($resid);
  290. header("Location:editTier5.php?Tier5ID=$tier5id");
  291. }
  292. if($id==3) {
  293. $sql = "Update resources Set FileInfo3= '' , DownloadPath3= '' , FileDescriptor3= '' Where ResourceId = '".$resid."' ";
  294. $result = mysql_query($sql,$dblink);
  295. $tier5id = base64_encode($resid);
  296. header("Location:editTier5.php?Tier5ID=$tier5id");
  297. }
  298. if($id==4) {
  299. $sql = "Update resources Set FileInfo4= '', DownloadPath4= '', FileDescriptor4= '' Where ResourceId = '".$resid."' ";
  300. $result = mysql_query($sql,$dblink);
  301. $tier5id = base64_encode($resid);
  302. header("Location:editTier5.php?Tier5ID=$tier5id");
  303. }
  304. }
  305. }
  306. ?>