/class/PHPExcel/Worksheet/Protection.php

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