/pma/libraries/PHPExcel/PHPExcel/Worksheet/Protection.php

https://bitbucket.org/kucing2k/ediassoc · PHP · 563 lines · 191 code · 55 blank · 317 comment · 3 complexity · 7f259681c7abfea7c3275794e8c94686 MD5 · raw file

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2010 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet
  23. * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.4, 2010-08-26
  26. */
  27. /**
  28. * PHPExcel_Worksheet_Protection
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet
  32. * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_Protection
  35. {
  36. /**
  37. * Sheet
  38. *
  39. * @var boolean
  40. */
  41. private $_sheet;
  42. /**
  43. * Objects
  44. *
  45. * @var boolean
  46. */
  47. private $_objects;
  48. /**
  49. * Scenarios
  50. *
  51. * @var boolean
  52. */
  53. private $_scenarios;
  54. /**
  55. * Format cells
  56. *
  57. * @var boolean
  58. */
  59. private $_formatCells;
  60. /**
  61. * Format columns
  62. *
  63. * @var boolean
  64. */
  65. private $_formatColumns;
  66. /**
  67. * Format rows
  68. *
  69. * @var boolean
  70. */
  71. private $_formatRows;
  72. /**
  73. * Insert columns
  74. *
  75. * @var boolean
  76. */
  77. private $_insertColumns;
  78. /**
  79. * Insert rows
  80. *
  81. * @var boolean
  82. */
  83. private $_insertRows;
  84. /**
  85. * Insert hyperlinks
  86. *
  87. * @var boolean
  88. */
  89. private $_insertHyperlinks;
  90. /**
  91. * Delete columns
  92. *
  93. * @var boolean
  94. */
  95. private $_deleteColumns;
  96. /**
  97. * Delete rows
  98. *
  99. * @var boolean
  100. */
  101. private $_deleteRows;
  102. /**
  103. * Select locked cells
  104. *
  105. * @var boolean
  106. */
  107. private $_selectLockedCells;
  108. /**
  109. * Sort
  110. *
  111. * @var boolean
  112. */
  113. private $_sort;
  114. /**
  115. * AutoFilter
  116. *
  117. * @var boolean
  118. */
  119. private $_autoFilter;
  120. /**
  121. * Pivot tables
  122. *
  123. * @var boolean
  124. */
  125. private $_pivotTables;
  126. /**
  127. * Select unlocked cells
  128. *
  129. * @var boolean
  130. */
  131. private $_selectUnlockedCells;
  132. /**
  133. * Password
  134. *
  135. * @var string
  136. */
  137. private $_password;
  138. /**
  139. * Create a new PHPExcel_Worksheet_Protection
  140. */
  141. public function __construct()
  142. {
  143. // Initialise values
  144. $this->_sheet = false;
  145. $this->_objects = false;
  146. $this->_scenarios = false;
  147. $this->_formatCells = false;
  148. $this->_formatColumns = false;
  149. $this->_formatRows = false;
  150. $this->_insertColumns = false;
  151. $this->_insertRows = false;
  152. $this->_insertHyperlinks = false;
  153. $this->_deleteColumns = false;
  154. $this->_deleteRows = false;
  155. $this->_selectLockedCells = false;
  156. $this->_sort = false;
  157. $this->_autoFilter = false;
  158. $this->_pivotTables = false;
  159. $this->_selectUnlockedCells = false;
  160. $this->_password = '';
  161. }
  162. /**
  163. * Is some sort of protection enabled?
  164. *
  165. * @return boolean
  166. */
  167. function isProtectionEnabled() {
  168. return $this->_sheet ||
  169. $this->_objects ||
  170. $this->_scenarios ||
  171. $this->_formatCells ||
  172. $this->_formatColumns ||
  173. $this->_formatRows ||
  174. $this->_insertColumns ||
  175. $this->_insertRows ||
  176. $this->_insertHyperlinks ||
  177. $this->_deleteColumns ||
  178. $this->_deleteRows ||
  179. $this->_selectLockedCells ||
  180. $this->_sort ||
  181. $this->_autoFilter ||
  182. $this->_pivotTables ||
  183. $this->_selectUnlockedCells;
  184. }
  185. /**
  186. * Get Sheet
  187. *
  188. * @return boolean
  189. */
  190. function getSheet() {
  191. return $this->_sheet;
  192. }
  193. /**
  194. * Set Sheet
  195. *
  196. * @param boolean $pValue
  197. * @return PHPExcel_Worksheet_Protection
  198. */
  199. function setSheet($pValue = false) {
  200. $this->_sheet = $pValue;
  201. return $this;
  202. }
  203. /**
  204. * Get Objects
  205. *
  206. * @return boolean
  207. */
  208. function getObjects() {
  209. return $this->_objects;
  210. }
  211. /**
  212. * Set Objects
  213. *
  214. * @param boolean $pValue
  215. * @return PHPExcel_Worksheet_Protection
  216. */
  217. function setObjects($pValue = false) {
  218. $this->_objects = $pValue;
  219. return $this;
  220. }
  221. /**
  222. * Get Scenarios
  223. *
  224. * @return boolean
  225. */
  226. function getScenarios() {
  227. return $this->_scenarios;
  228. }
  229. /**
  230. * Set Scenarios
  231. *
  232. * @param boolean $pValue
  233. * @return PHPExcel_Worksheet_Protection
  234. */
  235. function setScenarios($pValue = false) {
  236. $this->_scenarios = $pValue;
  237. return $this;
  238. }
  239. /**
  240. * Get FormatCells
  241. *
  242. * @return boolean
  243. */
  244. function getFormatCells() {
  245. return $this->_formatCells;
  246. }
  247. /**
  248. * Set FormatCells
  249. *
  250. * @param boolean $pValue
  251. * @return PHPExcel_Worksheet_Protection
  252. */
  253. function setFormatCells($pValue = false) {
  254. $this->_formatCells = $pValue;
  255. return $this;
  256. }
  257. /**
  258. * Get FormatColumns
  259. *
  260. * @return boolean
  261. */
  262. function getFormatColumns() {
  263. return $this->_formatColumns;
  264. }
  265. /**
  266. * Set FormatColumns
  267. *
  268. * @param boolean $pValue
  269. * @return PHPExcel_Worksheet_Protection
  270. */
  271. function setFormatColumns($pValue = false) {
  272. $this->_formatColumns = $pValue;
  273. return $this;
  274. }
  275. /**
  276. * Get FormatRows
  277. *
  278. * @return boolean
  279. */
  280. function getFormatRows() {
  281. return $this->_formatRows;
  282. }
  283. /**
  284. * Set FormatRows
  285. *
  286. * @param boolean $pValue
  287. * @return PHPExcel_Worksheet_Protection
  288. */
  289. function setFormatRows($pValue = false) {
  290. $this->_formatRows = $pValue;
  291. return $this;
  292. }
  293. /**
  294. * Get InsertColumns
  295. *
  296. * @return boolean
  297. */
  298. function getInsertColumns() {
  299. return $this->_insertColumns;
  300. }
  301. /**
  302. * Set InsertColumns
  303. *
  304. * @param boolean $pValue
  305. * @return PHPExcel_Worksheet_Protection
  306. */
  307. function setInsertColumns($pValue = false) {
  308. $this->_insertColumns = $pValue;
  309. return $this;
  310. }
  311. /**
  312. * Get InsertRows
  313. *
  314. * @return boolean
  315. */
  316. function getInsertRows() {
  317. return $this->_insertRows;
  318. }
  319. /**
  320. * Set InsertRows
  321. *
  322. * @param boolean $pValue
  323. * @return PHPExcel_Worksheet_Protection
  324. */
  325. function setInsertRows($pValue = false) {
  326. $this->_insertRows = $pValue;
  327. return $this;
  328. }
  329. /**
  330. * Get InsertHyperlinks
  331. *
  332. * @return boolean
  333. */
  334. function getInsertHyperlinks() {
  335. return $this->_insertHyperlinks;
  336. }
  337. /**
  338. * Set InsertHyperlinks
  339. *
  340. * @param boolean $pValue
  341. * @return PHPExcel_Worksheet_Protection
  342. */
  343. function setInsertHyperlinks($pValue = false) {
  344. $this->_insertHyperlinks = $pValue;
  345. return $this;
  346. }
  347. /**
  348. * Get DeleteColumns
  349. *
  350. * @return boolean
  351. */
  352. function getDeleteColumns() {
  353. return $this->_deleteColumns;
  354. }
  355. /**
  356. * Set DeleteColumns
  357. *
  358. * @param boolean $pValue
  359. * @return PHPExcel_Worksheet_Protection
  360. */
  361. function setDeleteColumns($pValue = false) {
  362. $this->_deleteColumns = $pValue;
  363. return $this;
  364. }
  365. /**
  366. * Get DeleteRows
  367. *
  368. * @return boolean
  369. */
  370. function getDeleteRows() {
  371. return $this->_deleteRows;
  372. }
  373. /**
  374. * Set DeleteRows
  375. *
  376. * @param boolean $pValue
  377. * @return PHPExcel_Worksheet_Protection
  378. */
  379. function setDeleteRows($pValue = false) {
  380. $this->_deleteRows = $pValue;
  381. return $this;
  382. }
  383. /**
  384. * Get SelectLockedCells
  385. *
  386. * @return boolean
  387. */
  388. function getSelectLockedCells() {
  389. return $this->_selectLockedCells;
  390. }
  391. /**
  392. * Set SelectLockedCells
  393. *
  394. * @param boolean $pValue
  395. * @return PHPExcel_Worksheet_Protection
  396. */
  397. function setSelectLockedCells($pValue = false) {
  398. $this->_selectLockedCells = $pValue;
  399. return $this;
  400. }
  401. /**
  402. * Get Sort
  403. *
  404. * @return boolean
  405. */
  406. function getSort() {
  407. return $this->_sort;
  408. }
  409. /**
  410. * Set Sort
  411. *
  412. * @param boolean $pValue
  413. * @return PHPExcel_Worksheet_Protection
  414. */
  415. function setSort($pValue = false) {
  416. $this->_sort = $pValue;
  417. return $this;
  418. }
  419. /**
  420. * Get AutoFilter
  421. *
  422. * @return boolean
  423. */
  424. function getAutoFilter() {
  425. return $this->_autoFilter;
  426. }
  427. /**
  428. * Set AutoFilter
  429. *
  430. * @param boolean $pValue
  431. * @return PHPExcel_Worksheet_Protection
  432. */
  433. function setAutoFilter($pValue = false) {
  434. $this->_autoFilter = $pValue;
  435. return $this;
  436. }
  437. /**
  438. * Get PivotTables
  439. *
  440. * @return boolean
  441. */
  442. function getPivotTables() {
  443. return $this->_pivotTables;
  444. }
  445. /**
  446. * Set PivotTables
  447. *
  448. * @param boolean $pValue
  449. * @return PHPExcel_Worksheet_Protection
  450. */
  451. function setPivotTables($pValue = false) {
  452. $this->_pivotTables = $pValue;
  453. return $this;
  454. }
  455. /**
  456. * Get SelectUnlockedCells
  457. *
  458. * @return boolean
  459. */
  460. function getSelectUnlockedCells() {
  461. return $this->_selectUnlockedCells;
  462. }
  463. /**
  464. * Set SelectUnlockedCells
  465. *
  466. * @param boolean $pValue
  467. * @return PHPExcel_Worksheet_Protection
  468. */
  469. function setSelectUnlockedCells($pValue = false) {
  470. $this->_selectUnlockedCells = $pValue;
  471. return $this;
  472. }
  473. /**
  474. * Get Password (hashed)
  475. *
  476. * @return string
  477. */
  478. function getPassword() {
  479. return $this->_password;
  480. }
  481. /**
  482. * Set Password
  483. *
  484. * @param string $pValue
  485. * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true
  486. * @return PHPExcel_Worksheet_Protection
  487. */
  488. function setPassword($pValue = '', $pAlreadyHashed = false) {
  489. if (!$pAlreadyHashed) {
  490. $pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
  491. }
  492. $this->_password = $pValue;
  493. return $this;
  494. }
  495. /**
  496. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  497. */
  498. public function __clone() {
  499. $vars = get_object_vars($this);
  500. foreach ($vars as $key => $value) {
  501. if (is_object($value)) {
  502. $this->$key = clone $value;
  503. } else {
  504. $this->$key = $value;
  505. }
  506. }
  507. }
  508. }