functions.common.trprofile.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* $Id: functions.common.trprofile.php 3307 2007-12-16 22:32:03Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * This method Gets Download profiles for a specific user (given by uid)
  17. *
  18. * @param $uid
  19. * @param $profile
  20. * @return array
  21. */
  22. function GetProfiles($uid, $profile) {
  23. global $cfg, $db;
  24. $profiles_array = array();
  25. $sql = "SELECT name FROM tf_trprofiles WHERE owner=".$db->qstr($uid)." AND public='0'";
  26. $rs = $db->GetCol($sql);
  27. if ($rs) {
  28. foreach($rs as $arr) {
  29. array_push($profiles_array, array(
  30. 'name' => $arr,
  31. 'is_selected' => ($arr == $profile) ? 1 : 0
  32. )
  33. );
  34. }
  35. }
  36. if ($db->ErrorNo() != 0) dbError($sql);
  37. return $profiles_array;
  38. }
  39. /**
  40. * This method Gets Download profiles for a specific user (given by username)
  41. *
  42. * @param $user
  43. * @param $profile
  44. * @return array
  45. */
  46. function GetProfilesByUserName($user, $profile) {
  47. global $cfg, $db;
  48. $profiles_array = array();
  49. $sql = "SELECT p.name AS name FROM tf_users AS u LEFT JOIN tf_trprofiles AS p ON (u.uid = p.owner) WHERE u.user_id=".$db->qstr($user)." AND p.public='0'";
  50. $rs = $db->GetCol($sql);
  51. if ($rs) {
  52. foreach($rs as $arr) {
  53. array_push($profiles_array, array(
  54. 'name' => $arr,
  55. 'is_selected' => ($arr == $profile) ? 1 : 0
  56. )
  57. );
  58. }
  59. }
  60. if ($db->ErrorNo() != 0) dbError($sql);
  61. return $profiles_array;
  62. }
  63. /**
  64. * This method Gets public Download profiles
  65. *
  66. * @param $profile
  67. * @return array
  68. */
  69. function GetPublicProfiles($profile) {
  70. global $cfg, $db;
  71. $profiles_array = array();
  72. $sql = "SELECT name FROM tf_trprofiles WHERE public= '1'";
  73. $rs = $db->GetCol($sql);
  74. if ($rs) {
  75. foreach($rs as $arr) {
  76. array_push($profiles_array, array(
  77. 'name' => $arr,
  78. 'is_selected' => ($arr == $profile) ? 1 : 0
  79. )
  80. );
  81. }
  82. }
  83. if ($db->ErrorNo() != 0) dbError($sql);
  84. return $profiles_array;
  85. }
  86. /**
  87. * This method fetch settings for an specific profile
  88. *
  89. * @param $profile
  90. * @return array
  91. */
  92. function GetProfileSettings($profile) {
  93. global $cfg, $db;
  94. $sql = "SELECT minport, maxport, maxcons, rerequest, rate, maxuploads, drate, runtime, sharekill, superseeder from tf_trprofiles where name=".$db->qstr($profile);
  95. $settings = $db->GetRow($sql);
  96. if ($db->ErrorNo() != 0) dbError($sql);
  97. return $settings;
  98. }
  99. /**
  100. * Add New Profile Information
  101. *
  102. * @param $newProfile
  103. */
  104. function AddProfileInfo( $newProfile ) {
  105. global $db, $cfg;
  106. $sql = 'INSERT INTO tf_trprofiles ( name , owner , minport , maxport , maxcons , rerequest , rate , maxuploads , drate , runtime , sharekill , superseeder , public )'
  107. ." VALUES ("
  108. . $db->qstr($newProfile["name"])
  109. .", ".$db->qstr($cfg['uid'])
  110. .", ".$db->qstr($newProfile["minport"])
  111. .", ".$db->qstr($newProfile["maxport"])
  112. .", ".$db->qstr($newProfile["maxcons"])
  113. .", ".$db->qstr($newProfile["rerequest"])
  114. .", ".$db->qstr($newProfile["rate"])
  115. .", ".$db->qstr($newProfile["maxuploads"])
  116. .", ".$db->qstr($newProfile["drate"])
  117. .", ".$db->qstr($newProfile["runtime"])
  118. .", ".$db->qstr($newProfile["sharekill"])
  119. .", ".$db->qstr($newProfile["superseeder"])
  120. .", ".$db->qstr($newProfile["public"]).")";
  121. $db->Execute( $sql );
  122. if ($db->ErrorNo() != 0) dbError($sql);
  123. }
  124. /**
  125. * getProfile
  126. *
  127. * @param $pid
  128. * @return
  129. */
  130. function getProfile($pid) {
  131. global $cfg, $db;
  132. $rtnValue = "";
  133. $sql = "SELECT id , name , minport , maxport , maxcons , rerequest , rate , maxuploads , drate , runtime , sharekill , superseeder , public FROM tf_trprofiles WHERE id=".$db->qstr($pid);
  134. $rtnValue = $db->GetAll($sql);
  135. return $rtnValue[0];
  136. }
  137. /**
  138. * Modify Profile Information
  139. *
  140. * @param $pid
  141. * @param $newProfile
  142. */
  143. function modProfileInfo($pid, $newProfile) {
  144. global $cfg, $db;
  145. $sql = "UPDATE tf_trprofiles SET"
  146. ." owner = ".$db->qstr($cfg['uid'])
  147. .", name = ".$db->qstr($newProfile["name"])
  148. .", minport = ".$db->qstr($newProfile["minport"])
  149. .", maxport = ".$db->qstr($newProfile["maxport"])
  150. .", maxcons = ".$db->qstr($newProfile["maxcons"])
  151. .", rerequest = ".$db->qstr($newProfile["rerequest"])
  152. .", rate = ".$db->qstr($newProfile["rate"])
  153. .", maxuploads = ".$db->qstr($newProfile["maxuploads"])
  154. .", drate = ".$db->qstr($newProfile["drate"])
  155. .", runtime = ".$db->qstr($newProfile["runtime"])
  156. .", sharekill = ".$db->qstr($newProfile["sharekill"])
  157. .", superseeder = ".$db->qstr($newProfile["superseeder"])
  158. .", public = ".$db->qstr($newProfile["public"])
  159. ." WHERE id = ".$db->qstr($pid);
  160. $db->Execute($sql);
  161. if ($db->ErrorNo() != 0) dbError($sql);
  162. }
  163. /**
  164. * Delete Profile Information
  165. *
  166. * @param $pid
  167. */
  168. function deleteProfileInfo($pid) {
  169. global $db;
  170. $sql = "DELETE FROM tf_trprofiles WHERE id=".$db->qstr($pid);
  171. $result = $db->Execute($sql);
  172. if ($db->ErrorNo() != 0) dbError($sql);
  173. }
  174. ?>