Protection.php 10.0 KB

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