├── LICENSE ├── README.md └── src ├── admin └── index.php ├── composer.json ├── config-dist.php ├── configure.php ├── connect.php ├── css ├── rateit.css └── rating.css ├── db.php ├── images ├── cross.gif ├── delete.gif ├── delete.png ├── edit.png ├── icon16.png ├── icon50.png ├── icon50_disabled.png ├── loading.gif ├── star.gif └── tick.gif ├── index.php ├── js ├── jquery-3.7.0.min.js ├── jquery-3.7.0.min.map ├── jquery.rateit.min.js ├── jquery.rateit.min.js.map └── rating.js ├── jwks.php ├── lib.php ├── rating.php ├── rating_tp.php ├── register.php ├── registration.php ├── share.php └── vendor └── autoload.php /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *Rating* is a simple application developed as a way to demonstrate how to build an IMS LTI tool provider using the [ceLTIc LTI class library](https://github.com/celtic-project/LTI-PHP). The application allows teachers to create items which can be rated by students. A separate list of items is maintained for each link from which the tool is launched. 2 | 3 | If the link has the Outcomes service enabled, then the associated gradebook column will be populated with the proportion of the visible items which each student has rated. 4 | 5 | If the tool consumer offers support for the Memberships service then a list of users can be displayed on the *manage consumers* page (with a list of group sets where also supported). For Moodle and Canvas the existing [API hooks](https://github.com/celtic-project/LTI-PHP/wiki/API-hooks) functionality in the LTI-PHP library can be used to add membership and group service support. 6 | 7 | If the Line Item service is also supported, then an additional line item is created for each item to be rated and will be populated with the students' raw scores for the item. 8 | 9 | The wiki area of this repository contains [documentation](https://github.com/celtic-project/Rating-PHP/wiki) for installing and using this application. 10 | -------------------------------------------------------------------------------- /src/admin/index.php: -------------------------------------------------------------------------------- 1 | 20 | * @copyright SPV Software Products 21 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 22 | */ 23 | require_once('../lib.php'); 24 | 25 | // Initialise session and database 26 | $db = null; 27 | $ok = init($db, false, 1); 28 | // Initialise parameters 29 | $id = null; 30 | if ($ok) { 31 | // Create LTI Tool instance 32 | $dataConnector = DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 33 | $tool = new Tool($dataConnector); 34 | // Check for platform id and action parameters 35 | $action = ''; 36 | if (isset($_REQUEST['id'])) { 37 | $id = intval($_REQUEST['id']); 38 | } 39 | if (isset($_REQUEST['do'])) { 40 | $action = $_REQUEST['do']; 41 | } 42 | 43 | // Process add platform action 44 | if ($action == 'add') { 45 | if (!empty($id) || !empty($_POST['name'])) { 46 | if (empty($id)) { 47 | $updatePlatform = new Platform($dataConnector); 48 | $updatePlatform->ltiVersion = LtiVersion::V1; 49 | } else { 50 | $updatePlatform = Platform::fromRecordId($id, $dataConnector); 51 | } 52 | if (!empty($_POST['key'])) { 53 | $updatePlatform->setKey($_POST['key']); 54 | } 55 | if (!empty($_POST['name'])) { 56 | $updatePlatform->name = $_POST['name']; 57 | } else { 58 | $updatePlatform->name = null; 59 | } 60 | if (!empty($_POST['secret'])) { 61 | $updatePlatform->secret = $_POST['secret']; 62 | } else { 63 | $updatePlatform->secret = null; 64 | } 65 | if (!empty($_POST['platformid'])) { 66 | $updatePlatform->platformId = $_POST['platformid']; 67 | } else { 68 | $updatePlatform->platformId = null; 69 | } 70 | if (!empty($_POST['clientid'])) { 71 | $updatePlatform->clientId = $_POST['clientid']; 72 | } else { 73 | $updatePlatform->clientId = null; 74 | } 75 | if (!empty($_POST['deploymentid'])) { 76 | $updatePlatform->deploymentId = $_POST['deploymentid']; 77 | } else { 78 | $updatePlatform->deploymentId = null; 79 | } 80 | if (!empty($_POST['authorizationserverid'])) { 81 | $updatePlatform->authorizationServerId = $_POST['authorizationserverid']; 82 | } else { 83 | $updatePlatform->authorizationServerId = null; 84 | } 85 | if (!empty($_POST['authenticationurl'])) { 86 | $updatePlatform->authenticationUrl = $_POST['authenticationurl']; 87 | } else { 88 | $updatePlatform->authenticationUrl = null; 89 | } 90 | if (!empty($_POST['accesstokenurl'])) { 91 | $updatePlatform->accessTokenUrl = $_POST['accesstokenurl']; 92 | } else { 93 | $updatePlatform->accessTokenUrl = null; 94 | } 95 | if (!empty($_POST['publickey'])) { 96 | $res = openssl_pkey_get_public($_POST['publickey']); 97 | if ($res === false) { 98 | $_SESSION['error_message'] = 'Invalid public key - value has not been changed.'; 99 | } else { 100 | $details = openssl_pkey_get_details($res); 101 | if (($details === false) || !isset($details['rsa'])) { 102 | $_SESSION['error_message'] = 'The public key must have a type of \'RSA\' - value has not been changed.'; 103 | } else { 104 | $updatePlatform->rsaKey = $_POST['publickey']; 105 | } 106 | } 107 | } else { 108 | $updatePlatform->rsaKey = null; 109 | } 110 | if (!empty($_POST['jku'])) { 111 | $updatePlatform->jku = $_POST['jku']; 112 | } else { 113 | $updatePlatform->jku = null; 114 | } 115 | if (!empty($_POST['ltiversion'])) { 116 | $updatePlatform->ltiVersion = LtiVersion::tryFrom($_POST['ltiversion']); 117 | if ($updatePlatform->ltiVersion === LtiVersion::V1P3) { 118 | $updatePlatform->signatureMethod = 'RS256'; 119 | } 120 | } 121 | $updatePlatform->enabled = isset($_POST['enabled']); 122 | $date = $_POST['enable_from']; 123 | if (empty($date)) { 124 | $updatePlatform->enableFrom = null; 125 | } else { 126 | $updatePlatform->enableFrom = strtotime($date); 127 | } 128 | $date = $_POST['enable_until']; 129 | if (empty($date)) { 130 | $updatePlatform->enableUntil = null; 131 | } else { 132 | $updatePlatform->enableUntil = strtotime($date); 133 | } 134 | $updatePlatform->protected = isset($_POST['protected']); 135 | $settings = $updatePlatform->getSettings(); 136 | foreach ($settings as $prop => $value) { 137 | if (strpos($prop, 'custom_') !== 0) { 138 | $updatePlatform->setSetting($prop); 139 | } 140 | } 141 | $properties = $_POST['properties']; 142 | $properties = str_replace("\r\n", "\n", $properties); 143 | $properties = explode("\n", $properties); 144 | foreach ($properties as $property) { 145 | if (strpos($property, '=') !== false) { 146 | list($name, $value) = explode('=', $property, 2); 147 | if ($name) { 148 | $updatePlatform->setSetting($name, $value); 149 | } 150 | } 151 | } 152 | $updatePlatform->debugMode = isset($_POST['debug']); 153 | // Ensure all required fields have been provided 154 | if ($updatePlatform->save()) { 155 | $_SESSION['message'] = 'The platform has been saved.'; 156 | } else { 157 | $_SESSION['error_message'] = 'Unable to save the platform; please check the data and try again.'; 158 | } 159 | } else { 160 | $_SESSION['error_message'] = 'Please enter a name.'; 161 | } 162 | header('Location: ./'); 163 | exit; 164 | // Process delete platform action 165 | } else if ($action == 'delete') { 166 | if ($_SERVER['REQUEST_METHOD'] === 'POST') { 167 | $ok = true; 168 | foreach ($_POST['ids'] as $id) { 169 | $platform = Platform::fromRecordId($id, $dataConnector); 170 | $ok = $ok && $platform->delete(); 171 | } 172 | if ($ok) { 173 | $_SESSION['message'] = 'The selected platforms have been deleted.'; 174 | } else { 175 | $_SESSION['error_message'] = 'Unable to delete at least one of the selected platforms; please try again.'; 176 | } 177 | } else { 178 | $platform = Platform::fromRecordId($id, $dataConnector); 179 | if ($platform->delete()) { 180 | $_SESSION['message'] = 'The platform has been deleted.'; 181 | } else { 182 | $_SESSION['error_message'] = 'Unable to delete the platform; please try again.'; 183 | } 184 | } 185 | header('Location: ./'); 186 | exit; 187 | } else { 188 | // Initialise an empty tool platform instance 189 | $updatePlatform = new Platform($dataConnector); 190 | $updatePlatform->secret = Util::getRandomString(32); 191 | } 192 | 193 | // Fetch a list of existing tool platform records 194 | $platforms = $tool->getPlatforms(); 195 | 196 | // Set launch URL for information 197 | $launchUrl = getAppUrl(1) . 'connect.php'; 198 | 199 | // Set launch URL for information 200 | $jwksUrl = getAppUrl(1) . 'jwks.php'; 201 | 202 | // Set Canvas configure URL for information 203 | $configureUrl = getAppUrl(1) . 'configure.php'; 204 | } 205 | 206 | $here = function($val) { 207 | return $val; 208 | }; 209 | 210 | // Page header 211 | $page = <<< EOD 212 | 213 | 214 | 215 | 216 | 217 | {$here(APP_NAME)}: Manage platforms 218 | 219 | 258 | 259 | 260 | 261 |

{$here(APP_NAME)}: Manage platforms

262 | 263 | EOD; 264 | 265 | // Display warning message if access does not appear to have been restricted 266 | if (!(isset($_SERVER['AUTH_TYPE']) && isset($_SERVER['REMOTE_USER']) && isset($_SERVER['PHP_AUTH_PW']))) { 267 | $page .= <<< EOD 268 |

*** WARNING *** Access to this page should be restricted to application administrators only.

269 | 270 | EOD; 271 | } 272 | 273 | // Check for any messages to be displayed 274 | if (isset($_SESSION['error_message'])) { 275 | $page .= <<< EOD 276 |

ERROR: {$_SESSION['error_message']}

277 | 278 | EOD; 279 | unset($_SESSION['error_message']); 280 | } 281 | 282 | if (isset($_SESSION['message'])) { 283 | $page .= <<< EOD 284 |

{$_SESSION['message']}

285 | 286 | EOD; 287 | unset($_SESSION['message']); 288 | } 289 | 290 | // Display table of existing platform records 291 | if ($ok) { 292 | 293 | if (count($platforms) <= 0) { 294 | $page .= <<< EOD 295 |

No platforms have been added yet.

296 | 297 | EOD; 298 | } else { 299 | $page .= <<< EOD 300 |
301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | EOD; 321 | foreach ($platforms as $platform) { 322 | $trid = urlencode($platform->getRecordId()); 323 | if ($platform->getRecordId() === $id) { 324 | $updatePlatform = $platform; 325 | } 326 | if (!$platform->getIsAvailable()) { 327 | $available = 'cross'; 328 | $availableAlt = 'Not available'; 329 | $trclass = 'notvisible'; 330 | } else { 331 | $available = 'tick'; 332 | $availableAlt = 'Available'; 333 | $trclass = ''; 334 | } 335 | if ($platform->protected) { 336 | $protected = 'tick'; 337 | $protectedAlt = 'Protected'; 338 | } else { 339 | $protected = 'cross'; 340 | $protectedAlt = 'Not protected'; 341 | } 342 | if ($platform->debugMode) { 343 | $debug = 'tick'; 344 | $debugAlt = 'Enabled'; 345 | } else { 346 | $debug = 'cross'; 347 | $debugAlt = 'Disabled'; 348 | } 349 | if (is_null($platform->lastAccess)) { 350 | $last = 'None'; 351 | } else { 352 | $last = date('j-M-Y', $platform->lastAccess); 353 | } 354 | $page .= <<< EOD 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 370 | 371 | 372 | EOD; 373 | } 374 | $page .= <<< EOD 375 | 376 |
 NameKeyPlatform IDClient IDDeployment IDVersionAvailable?Protected?Debug?Last accessOptions
{$platform->name}{$platform->getKey()}{$platform->platformId}{$platform->clientId}{$platform->deploymentId}{$platform->consumerVersion}{$availableAlt}{$protectedAlt}{$debugAlt}{$last} 368 | Edit platform Delete platform 369 |
377 |

378 | 379 |

380 |
381 | 382 | EOD; 383 | } 384 | 385 | // Display form for adding/editing a platform 386 | $update = ''; 387 | $lti2 = ''; 388 | if (!isset($updatePlatform->created)) { 389 | $mode = 'Add new'; 390 | } else { 391 | $mode = 'Update'; 392 | $update = ' disabled="disabled"'; 393 | if ($updatePlatform->ltiVersion === LtiVersion::V2) { 394 | $lti2 = ' disabled="disabled"'; 395 | } 396 | } 397 | $name = ratingHtmlEntities($updatePlatform->name); 398 | $key = ratingHtmlEntities($updatePlatform->getKey()); 399 | $platformId = ratingHtmlEntities($updatePlatform->platformId); 400 | $clientId = ratingHtmlEntities($updatePlatform->clientId); 401 | $deploymentId = ratingHtmlEntities($updatePlatform->deploymentId); 402 | $authorizationServerId = ratingHtmlEntities($updatePlatform->authorizationServerId); 403 | $authenticationUrl = ratingHtmlEntities($updatePlatform->authenticationUrl); 404 | $accessTokenUrl = ratingHtmlEntities($updatePlatform->accessTokenUrl); 405 | $publicKey = ratingHtmlEntities($updatePlatform->rsaKey); 406 | $jku = ratingHtmlEntities($updatePlatform->jku); 407 | $secret = ratingHtmlEntities($updatePlatform->secret); 408 | if ($updatePlatform->enabled) { 409 | $enabled = ' checked="checked"'; 410 | } else { 411 | $enabled = ''; 412 | } 413 | $enableFrom = ''; 414 | if (!is_null($updatePlatform->enableFrom)) { 415 | $enableFrom = date('j-M-Y H:i', $updatePlatform->enableFrom); 416 | } 417 | $enableUntil = ''; 418 | if (!is_null($updatePlatform->enableUntil)) { 419 | $enableUntil = date('j-M-Y H:i', $updatePlatform->enableUntil); 420 | } 421 | if ($updatePlatform->protected) { 422 | $protected = ' checked="checked"'; 423 | } else { 424 | $protected = ''; 425 | } 426 | $properties = ''; 427 | $settings = $updatePlatform->getSettings(); 428 | foreach ($settings as $prop => $value) { 429 | if (strpos($prop, 'custom_') !== 0) { 430 | $properties .= "{$prop}={$value}\n"; 431 | } 432 | } 433 | if ($updatePlatform->debugMode) { 434 | $debug = ' checked="checked"'; 435 | } else { 436 | $debug = ''; 437 | } 438 | $v1 = LtiVersion::V1->value; 439 | $v1p3 = LtiVersion::V1P3->value; 440 | $v1Selected = ' selected'; 441 | $v1p3Selected = ''; 442 | if ($updatePlatform->ltiVersion === LtiVersion::V1P3) { 443 | $v1Selected = ''; 444 | $v1p3Selected = ' selected'; 445 | } 446 | 447 | $page .= <<< EOD 448 |

{$mode} platform

449 | 450 |
451 |
452 | LTI version: 
456 |
457 | Name:* 

458 | Key: 
459 | Secret: 
460 | Platform ID: 
461 | Client ID: 
462 | Deployment ID: 
463 | Authorization server ID: 
464 | Authentication request URL: 
465 | Access token URL: 
466 | Public key: 
469 | JSON webkey URL (jku): 
470 |
471 | Enabled? 
472 | Enable from: 
473 | Enable until: 
474 | Protected? 
475 | Properties: 
476 | Debug mode? 
477 |
478 | 479 | 480 | * = required field  481 | 482 | EOD; 483 | 484 | if (isset($updatePlatform->created)) { 485 | $page .= <<< EOD 486 |   487 | 488 | EOD; 489 | } 490 | $page .= <<< EOD 491 |
492 |
    493 |
  • Launch URL, initiate login URL, redirection URI, registration URL: {$launchUrl}
  • 494 |
  • Public keyset URL: {$jwksUrl}
  • 495 |
  • Canvas configuration URLs: {$configureUrl} (XML) and {$configureUrl}?json (JSON)
  • 496 |
497 |
498 | 499 | EOD; 500 | } 501 | 502 | // Page footer 503 | $page .= pageFooter(); 504 | $page .= <<< EOD 505 | 506 | 507 | 508 | EOD; 509 | 510 | // Display page 511 | echo $page; 512 | ?> 513 | -------------------------------------------------------------------------------- /src/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "celtic/rating", 3 | "version": "5.0.0", 4 | "type": "project", 5 | "license": "GPL-3.0-or-later", 6 | "authors": [ 7 | { 8 | "name": "Stephen P Vickers", 9 | "email": "stephen@spvsoftwareproducts.com" 10 | } 11 | ], 12 | "support": { 13 | "docs": "https://github.com/celtic-project/Rating-PHP/wiki" 14 | }, 15 | "require": { 16 | "php": ">=8.1", 17 | "celtic/lti": "^5.0.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/config-dist.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright SPV Software Products 11 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 12 | */ 13 | ### 14 | ### Application settings 15 | ### 16 | // Uncomment the next line to log all PHP messages 17 | // error_reporting(E_ALL); 18 | // Set the application logging level 19 | Util::$logLevel = LogLevel::Error; 20 | 21 | // Specify a prefix (starting with '/') when the REQUEST_URI server variable is missing the first part of the real path 22 | define('REQUEST_URI_PREFIX', ''); 23 | 24 | ### 25 | ### Database connection settings 26 | ### 27 | define('DB_NAME', ''); // e.g. 'mysql:dbname=MyDb;host=localhost' or 'sqlite:php-rating.sqlitedb' 28 | define('DB_USERNAME', ''); 29 | define('DB_PASSWORD', ''); 30 | define('DB_TABLENAME_PREFIX', ''); 31 | 32 | ### 33 | ### LTI 1.3 Security settings 34 | ### 35 | define('SIGNATURE_METHOD', 'RS256'); 36 | define('KID', ''); // A random string to identify the key value 37 | define('PRIVATE_KEY', <<< EOD 38 | -----BEGIN RSA PRIVATE KEY----- 39 | Insert private key here 40 | -----END RSA PRIVATE KEY----- 41 | EOD 42 | ); 43 | 44 | ### 45 | ### Dynamic registration settings 46 | ### 47 | define('AUTO_ENABLE', false); 48 | define('ENABLE_FOR_DAYS', 0); 49 | ?> 50 | -------------------------------------------------------------------------------- /src/configure.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright SPV Software Products 10 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 11 | */ 12 | require_once('lib.php'); 13 | 14 | $url = getAppUrl(); 15 | $domain = parse_url($url, PHP_URL_HOST); 16 | 17 | $here = function($val) { 18 | return $val; 19 | }; 20 | 21 | if (!isset($_GET['json'])) { 22 | $xml = <<< EOD 23 | 24 | 33 | {$here(APP_NAME)} 34 | Access to {$here(APP_NAME)} using LTI 35 | {$url}images/icon16.png 36 | {$url}connect.php 37 | 38 | rating 39 | public 40 | {$domain} 41 | true 42 | 43 | 44 | spvsp 45 | SPV Software Products 46 | Provider of open source educational tools. 47 | http://www.spvsoftwareproducts.com/ 48 | 49 | stephen@spvsoftwareproducts.com 50 | 51 | 52 | 53 | EOD; 54 | 55 | header("Content-Type: application/xml; "); 56 | 57 | echo $xml; 58 | } else { 59 | 60 | $json = <<< EOD 61 | { 62 | "title": "{$here(APP_NAME)}", 63 | "description": "Access to {$here(APP_NAME)} using LTI", 64 | "privacy_level": "public", 65 | "oidc_initiation_url": "{$url}connect.php", 66 | "target_link_uri": "{$url}connect.php", 67 | "scopes": [ 68 | "{$here(LTI\Service\LineItem::$SCOPE)}", 69 | "{$here(LTI\Service\Score::$SCOPE)}", 70 | "{$here(LTI\Service\Membership::$SCOPE)}" 71 | ], 72 | "extensions": [ 73 | { 74 | "domain": "{$domain}", 75 | "tool_id": "rating", 76 | "platform": "canvas.instructure.com", 77 | "privacy_level": "public", 78 | "settings": { 79 | "text": "{$here(APP_NAME)}", 80 | "icon_url": "{$url}icon16.png", 81 | "placements": [ 82 | { 83 | "placement": "assignment_selection", 84 | "message_type": "LtiDeepLinkingRequest" 85 | } 86 | ] 87 | } 88 | } 89 | ], 90 | "public_jwk_url": "{$url}jwks.php", 91 | "custom_fields": { 92 | "canvas_course_id": "$Canvas.course.id" 93 | } 94 | } 95 | EOD; 96 | 97 | header("Content-Type: application/json; "); 98 | 99 | echo $json; 100 | } 101 | ?> -------------------------------------------------------------------------------- /src/connect.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright SPV Software Products 10 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 11 | */ 12 | require_once('rating_tp.php'); 13 | 14 | // Cancel any existing session 15 | session_name(SESSION_NAME); 16 | session_start(); 17 | $_SESSION = array(); 18 | session_destroy(); 19 | 20 | // Initialise database 21 | $db = null; 22 | if (init($db)) { 23 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 24 | $tool = new RatingTool($dataConnector); 25 | $tool->setParameterConstraint('resource_link_id', true, 50, array('basic-lti-launch-request')); 26 | $tool->setParameterConstraint('user_id', true, 50, array('basic-lti-launch-request')); 27 | $tool->setParameterConstraint('roles', true, null, array('basic-lti-launch-request')); 28 | } else { 29 | $tool = new RatingTool(null); 30 | $tool->reason = $_SESSION['error_message']; 31 | } 32 | $tool->handleRequest(); 33 | ?> 34 | -------------------------------------------------------------------------------- /src/css/rateit.css: -------------------------------------------------------------------------------- 1 | .rateit { 2 | display: -moz-inline-box; 3 | display: inline-block; 4 | position: relative; 5 | -webkit-user-select: none; 6 | -khtml-user-select: none; 7 | -moz-user-select: none; 8 | -o-user-select: none; 9 | -ms-user-select: none; 10 | user-select: none; 11 | -webkit-touch-callout: none; 12 | } 13 | 14 | .rateit .rateit-range { 15 | position: relative; 16 | display: -moz-inline-box; 17 | display: inline-block; 18 | background: url(star.gif); 19 | height: 16px; 20 | outline: none; 21 | } 22 | 23 | .rateit .rateit-range * { 24 | display: block; 25 | } 26 | 27 | /* for IE 6 */ 28 | * html .rateit, * html .rateit .rateit-range { 29 | display: inline; 30 | } 31 | 32 | /* for IE 7 */ 33 | * + html .rateit, * + html .rateit .rateit-range { 34 | display: inline; 35 | } 36 | 37 | .rateit .rateit-hover, .rateit .rateit-selected { 38 | position: absolute; 39 | left: 0; 40 | top: 0; 41 | width: 0; 42 | } 43 | 44 | .rateit .rateit-hover-rtl, .rateit .rateit-selected-rtl { 45 | left: auto; 46 | right: 0; 47 | } 48 | 49 | .rateit .rateit-hover { 50 | background: url(star.gif) left -32px; 51 | color: rgb(239, 197, 41); 52 | } 53 | 54 | .rateit .rateit-hover-rtl { 55 | background-position: right -32px; 56 | } 57 | 58 | .rateit .rateit-selected { 59 | background: url(star.gif) left -16px; 60 | color: rgb(191,66,66); 61 | } 62 | 63 | .rateit .rateit-selected-rtl { 64 | background-position: right -16px; 65 | } 66 | 67 | .rateit .rateit-preset { 68 | background: url(star.gif) left -48px; 69 | color: rgb(239, 107, 34); 70 | } 71 | 72 | .rateit .rateit-preset-rtl { 73 | background: url(star.gif) right -48px; 74 | } 75 | 76 | .rateit button.rateit-reset { 77 | background: url(delete.gif) 0 0; 78 | width: 16px; 79 | height: 16px; 80 | display: -moz-inline-box; 81 | display: inline-block; 82 | float: left; 83 | outline: none; 84 | border: none; 85 | padding: 0; 86 | } 87 | 88 | .rateit .rateit-reset span { 89 | display: none; 90 | } 91 | 92 | .rateit button.rateit-reset:hover, .rateit button.rateit-reset:focus { 93 | background-position: 0 -16px; 94 | } 95 | 96 | 97 | .rateit-font { 98 | font-size: 24px; 99 | line-height: 1em; 100 | } 101 | 102 | .rateit-font .rateit-range { 103 | background: none; 104 | height: auto; 105 | } 106 | 107 | .rateit-font .rateit-empty { 108 | color: #ccc; 109 | } 110 | 111 | .rateit-font .rateit-range > div, .rateit-font .rateit-range > span { 112 | background: none; 113 | overflow: hidden; 114 | cursor: default; 115 | } 116 | 117 | .rateit.rateit-font .rateit-reset { 118 | font-size: inherit; 119 | background: none; 120 | width: 0.6em; 121 | height: 0.6em; 122 | margin-top: 0.2em; 123 | background: gray; 124 | border-radius: 50%; 125 | position: relative; 126 | } 127 | 128 | .rateit.rateit-font .rateit-reset span { 129 | display: block; 130 | font-weight: bold; 131 | color: white; 132 | height: calc(50% - 0.045em); 133 | top: 0; 134 | position: absolute; 135 | border-bottom: 0.09em solid white; 136 | width: 72%; 137 | margin-left: 14%; 138 | } 139 | 140 | 141 | .rateit.rateit-font .rateit-reset:hover, .rateit.rateit-font button.rateit-reset:focus { 142 | background: #e6574b; /* Old browsers */ 143 | background: radial-gradient(ellipse at center, #e6574b 55%,#f6836b 77%,#f9d3cc 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ 144 | background-position: 0 0; 145 | } 146 | -------------------------------------------------------------------------------- /src/css/rating.css: -------------------------------------------------------------------------------- 1 | table.items, table.shares, table.users, table.lineitems { 2 | border: 1; 3 | margin: 10px; 4 | } 5 | table.shares, table.users, table.lineitems { 6 | border-collapse: collapse; 7 | } 8 | table.shares tr th, table.shares td, table.users tr th, table.users td, table.lineitems tr th, table.lineitems td { 9 | border: 1px solid #000; 10 | } 11 | tr.notvisible { 12 | background-color: #c0c0c0; 13 | } 14 | tr.oddrow { 15 | background-color: #ffff80; 16 | } 17 | tr.evenrow { 18 | background-color: #80ffff; 19 | } 20 | span.title { 21 | font-weight: bold; 22 | } 23 | span.title a { 24 | text-decoration: none; 25 | } 26 | .aligncentre { 27 | text-align: center; 28 | } 29 | .alignright { 30 | text-align: right; 31 | } 32 | span.label { 33 | display: inline-block; 34 | width: 11em; 35 | vertical-align: top; 36 | } 37 | .box { 38 | float: left; 39 | border: 2px dashed #00f; 40 | padding: 1em; 41 | margin-left: 10px; 42 | background-color: #ffffc0; 43 | } 44 | .sharebox { 45 | float: right; 46 | border: 2px dotted #000; 47 | padding: 1em; 48 | margin-right: 10px; 49 | background-color: #ffffc0; 50 | text-align: center; 51 | } 52 | h1 { 53 | font-size: 120%; 54 | color: #00f; 55 | } 56 | h2 { 57 | font-size: 110%; 58 | color: #00f; 59 | margin: 0; 60 | margin-left: 10px; 61 | padding-top: 10px; 62 | } 63 | img { 64 | border: 0; 65 | } 66 | .iconcolumn { 67 | width: 40px; 68 | } 69 | .required { 70 | color: #f00; 71 | } 72 | .clear { 73 | clear: both; 74 | padding-top: 10px; 75 | } 76 | .success, .error { 77 | border: 1px solid; 78 | padding: .75rem 1.25rem; 79 | margin-bottom: 1rem; 80 | } 81 | .success { 82 | color: #155724; 83 | background-color: #d4edda; 84 | border-color: #c3e6cb; 85 | } 86 | .error { 87 | color: #721c24; 88 | background-color: #f8d7da; 89 | border-color: #f5c6cb; 90 | } 91 | .hide { 92 | display: none; 93 | } 94 | button { 95 | border: 1px solid transparent; 96 | padding: 0.375rem 0.75rem; 97 | font-size: 1rem; 98 | line-height: 1.5; 99 | border-radius: 0.25rem; 100 | color: #fff; 101 | background-color: #007bff; 102 | border-color: #007bff; 103 | text-align: center; 104 | text-decoration: none; 105 | display: inline-block; 106 | cursor: pointer; 107 | } 108 | footer { 109 | width: 100%; 110 | margin-top: 1em; 111 | padding: 5px 0 5px 0; 112 | background-color: #f5f5f5; 113 | text-align: center; 114 | font-size: 80%; 115 | } 116 | -------------------------------------------------------------------------------- /src/db.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright SPV Software Products 12 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 13 | */ 14 | require_once('vendor/autoload.php'); 15 | 16 | // Set the default application logging level 17 | Util::$logLevel = LogLevel::Error; 18 | 19 | require_once('config.php'); 20 | 21 | ### 22 | ### Return a connection to the database, return false if an error occurs 23 | ### 24 | 25 | function open_db() 26 | { 27 | try { 28 | $db = new PDO(DB_NAME, DB_USERNAME, DB_PASSWORD); 29 | } catch (PDOException $e) { 30 | $db = false; 31 | $_SESSION['error_message'] = "Database error {$e->getCode()}: {$e->getMessage()}"; 32 | } 33 | 34 | return $db; 35 | } 36 | 37 | ### 38 | ### Check if a table exists 39 | ### 40 | 41 | function tableExists($db, $name) 42 | { 43 | $sql = "select 1 from {$name}"; 44 | $query = $db->prepare($sql); 45 | try { 46 | $ok = $query->execute() !== false; 47 | } catch (PDOException $e) { 48 | $ok = false; 49 | } 50 | 51 | return $ok; 52 | } 53 | 54 | ### 55 | ### Create any missing database tables (only for MySQL and SQLite databases) 56 | ### 57 | 58 | function init_db($db) 59 | { 60 | $dbType = ''; 61 | $pos = strpos(DB_NAME, ':'); 62 | if ($pos !== false) { 63 | $dbType = strtolower(substr(DB_NAME, 0, $pos)); 64 | } 65 | 66 | $ok = true; 67 | $prefix = DB_TABLENAME_PREFIX; 68 | 69 | if (!tableExists($db, $prefix . DataConnector\DataConnector::PLATFORM_TABLE_NAME)) { 70 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' (' . 71 | 'consumer_pk int(11) NOT NULL AUTO_INCREMENT, ' . 72 | 'name varchar(50) NOT NULL, ' . 73 | 'consumer_key varchar(256) DEFAULT NULL, ' . 74 | 'secret varchar(1024) DEFAULT NULL, ' . 75 | 'platform_id varchar(255) DEFAULT NULL, ' . 76 | 'client_id varchar(255) DEFAULT NULL, ' . 77 | 'deployment_id varchar(255) DEFAULT NULL, ' . 78 | 'public_key text DEFAULT NULL, ' . 79 | 'lti_version varchar(10) DEFAULT NULL, ' . 80 | 'signature_method varchar(15) DEFAULT NULL, ' . 81 | 'consumer_name varchar(255) DEFAULT NULL, ' . 82 | 'consumer_version varchar(255) DEFAULT NULL, ' . 83 | 'consumer_guid varchar(1024) DEFAULT NULL, ' . 84 | 'profile text DEFAULT NULL, ' . 85 | 'tool_proxy text DEFAULT NULL, ' . 86 | 'settings text DEFAULT NULL, ' . 87 | 'protected tinyint(1) NOT NULL, ' . 88 | 'enabled tinyint(1) NOT NULL, ' . 89 | 'enable_from datetime DEFAULT NULL, ' . 90 | 'enable_until datetime DEFAULT NULL, ' . 91 | 'last_access date DEFAULT NULL, ' . 92 | 'created datetime NOT NULL, ' . 93 | 'updated datetime NOT NULL, ' . 94 | 'PRIMARY KEY (consumer_pk)' . 95 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 96 | $ok = $db->exec($sql) !== false; 97 | if ($ok) { 98 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' ' . 99 | "ADD UNIQUE INDEX {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . '_' . 100 | 'consumer_key_UNIQUE (consumer_key ASC)'; 101 | $ok = $db->exec($sql) !== false; 102 | } 103 | if ($ok) { 104 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' ' . 105 | "ADD UNIQUE INDEX {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . '_' . 106 | 'platform_UNIQUE (platform_id ASC, client_id ASC, deployment_id ASC)'; 107 | $ok = $db->exec($sql) !== false; 108 | } 109 | } 110 | 111 | if ($ok && !tableExists($db, $prefix . DataConnector\DataConnector::NONCE_TABLE_NAME)) { 112 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::NONCE_TABLE_NAME . ' (' . 113 | 'consumer_pk int(11) NOT NULL, ' . 114 | 'value varchar(50) NOT NULL, ' . 115 | 'expires datetime NOT NULL, ' . 116 | 'PRIMARY KEY (consumer_pk, value)' . 117 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 118 | $ok = $db->exec($sql) !== false; 119 | if ($ok) { 120 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::NONCE_TABLE_NAME . ' ' . 121 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::NONCE_TABLE_NAME . '_' . 122 | DataConnector\DataConnector::PLATFORM_TABLE_NAME . '_FK1 FOREIGN KEY (consumer_pk) ' . 123 | "REFERENCES {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' (consumer_pk)'; 124 | $ok = $db->exec($sql) !== false; 125 | } 126 | } 127 | 128 | if ($ok && !tableExists($db, $prefix . DataConnector\DataConnector::ACCESS_TOKEN_TABLE_NAME)) { 129 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::ACCESS_TOKEN_TABLE_NAME . ' (' . 130 | 'consumer_pk int(11) NOT NULL, ' . 131 | 'scopes text NOT NULL, ' . 132 | 'token varchar(2000) NOT NULL, ' . 133 | 'expires datetime NOT NULL, ' . 134 | 'created datetime NOT NULL, ' . 135 | 'updated datetime NOT NULL, ' . 136 | 'PRIMARY KEY (consumer_pk)' . 137 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 138 | $ok = $db->exec($sql) !== false; 139 | if ($ok) { 140 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::ACCESS_TOKEN_TABLE_NAME . ' ' . 141 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::ACCESS_TOKEN_TABLE_NAME . '_' . 142 | DataConnector\DataConnector::PLATFORM_TABLE_NAME . '_FK1 FOREIGN KEY (consumer_pk) ' . 143 | "REFERENCES {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' (consumer_pk)'; 144 | $ok = $db->exec($sql) !== false; 145 | } 146 | } 147 | 148 | if (!tableExists($db, $prefix . DataConnector\DataConnector::CONTEXT_TABLE_NAME)) { 149 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::CONTEXT_TABLE_NAME . ' (' . 150 | 'context_pk int(11) NOT NULL AUTO_INCREMENT, ' . 151 | 'consumer_pk int(11) NOT NULL, ' . 152 | 'lti_context_id varchar(255) NOT NULL, ' . 153 | 'title varchar(255) DEFAULT NULL, ' . 154 | 'type varchar(50) DEFAULT NULL, ' . 155 | 'settings text DEFAULT NULL, ' . 156 | 'created datetime NOT NULL, ' . 157 | 'updated datetime NOT NULL, ' . 158 | 'PRIMARY KEY (context_pk)' . 159 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 160 | $ok = $db->exec($sql) !== false; 161 | if ($ok) { 162 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::CONTEXT_TABLE_NAME . ' ' . 163 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::CONTEXT_TABLE_NAME . '_' . 164 | DataConnector\DataConnector::PLATFORM_TABLE_NAME . '_FK1 FOREIGN KEY (consumer_pk) ' . 165 | "REFERENCES {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' (consumer_pk)'; 166 | $ok = $db->exec($sql) !== false; 167 | } 168 | if ($ok) { 169 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::CONTEXT_TABLE_NAME . ' ' . 170 | "ADD INDEX {$prefix}" . DataConnector\DataConnector::CONTEXT_TABLE_NAME . '_' . 171 | 'consumer_id_IDX (consumer_pk ASC)'; 172 | $ok = $db->exec($sql) !== false; 173 | } 174 | } 175 | 176 | if ($ok && !tableExists($db, $prefix . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME)) { 177 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' (' . 178 | 'resource_link_pk int(11) AUTO_INCREMENT, ' . 179 | 'context_pk int(11) DEFAULT NULL, ' . 180 | 'consumer_pk int(11) DEFAULT NULL, ' . 181 | 'title varchar(255) DEFAULT NULL, ' . 182 | 'lti_resource_link_id varchar(255) NOT NULL, ' . 183 | 'settings text, ' . 184 | 'primary_resource_link_pk int(11) DEFAULT NULL, ' . 185 | 'share_approved tinyint(1) DEFAULT NULL, ' . 186 | 'created datetime NOT NULL, ' . 187 | 'updated datetime NOT NULL, ' . 188 | 'PRIMARY KEY (resource_link_pk)' . 189 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 190 | $ok = $db->exec($sql) !== false; 191 | if ($ok) { 192 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 193 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_' . 194 | DataConnector\DataConnector::PLATFORM_TABLE_NAME . '_FK1 FOREIGN KEY (consumer_pk) ' . 195 | "REFERENCES {$prefix}" . DataConnector\DataConnector::PLATFORM_TABLE_NAME . ' (consumer_pk)'; 196 | $ok = $db->exec($sql) !== false; 197 | } 198 | if ($ok) { 199 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 200 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_' . 201 | DataConnector\DataConnector::CONTEXT_TABLE_NAME . '_FK1 FOREIGN KEY (context_pk) ' . 202 | "REFERENCES {$prefix}" . DataConnector\DataConnector::CONTEXT_TABLE_NAME . ' (context_pk)'; 203 | $ok = $db->exec($sql) !== false; 204 | } 205 | if ($ok) { 206 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 207 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_' . 208 | DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_FK1 FOREIGN KEY (primary_resource_link_pk) ' . 209 | "REFERENCES {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' (resource_link_pk)'; 210 | $ok = $db->exec($sql) !== false; 211 | } 212 | if ($ok) { 213 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 214 | "ADD INDEX {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_' . 215 | 'consumer_pk_IDX (consumer_pk ASC)'; 216 | $ok = $db->exec($sql) !== false; 217 | } 218 | if ($ok) { 219 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' . 220 | "ADD INDEX {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_' . 221 | 'context_pk_IDX (context_pk ASC)'; 222 | $ok = $db->exec($sql) !== false; 223 | } 224 | } 225 | 226 | if ($ok && !tableExists($db, $prefix . DataConnector\DataConnector::USER_RESULT_TABLE_NAME)) { 227 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::USER_RESULT_TABLE_NAME . ' (' . 228 | 'user_result_pk int(11) AUTO_INCREMENT, ' . 229 | 'resource_link_pk int(11) NOT NULL, ' . 230 | 'lti_user_id varchar(255) NOT NULL, ' . 231 | 'lti_result_sourcedid varchar(1024) NOT NULL, ' . 232 | 'created datetime NOT NULL, ' . 233 | 'updated datetime NOT NULL, ' . 234 | 'PRIMARY KEY (user_result_pk)' . 235 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 236 | $ok = $db->exec($sql) !== false; 237 | if ($ok) { 238 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::USER_RESULT_TABLE_NAME . ' ' . 239 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::USER_RESULT_TABLE_NAME . '_' . 240 | DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_FK1 FOREIGN KEY (resource_link_pk) ' . 241 | "REFERENCES {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' (resource_link_pk)'; 242 | $ok = $db->exec($sql) !== false; 243 | } 244 | if ($ok) { 245 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::USER_RESULT_TABLE_NAME . ' ' . 246 | "ADD INDEX {$prefix}" . DataConnector\DataConnector::USER_RESULT_TABLE_NAME . '_' . 247 | 'resource_link_pk_IDX (resource_link_pk ASC)'; 248 | $ok = $db->exec($sql) !== false; 249 | } 250 | } 251 | 252 | if ($ok && !tableExists($db, $prefix . DataConnector\DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME)) { 253 | $sql = "CREATE TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' (' . 254 | 'share_key_id varchar(32) NOT NULL, ' . 255 | 'resource_link_pk int(11) NOT NULL, ' . 256 | 'auto_approve tinyint(1) NOT NULL, ' . 257 | 'expires datetime NOT NULL, ' . 258 | 'PRIMARY KEY (share_key_id)' . 259 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 260 | $ok = $db->exec($sql) !== false; 261 | if ($ok) { 262 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . 263 | "ADD CONSTRAINT {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '_' . 264 | DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_FK1 FOREIGN KEY (resource_link_pk) ' . 265 | "REFERENCES {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' (resource_link_pk)'; 266 | $ok = $db->exec($sql) !== false; 267 | } 268 | if ($ok) { 269 | $sql = "ALTER TABLE {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' . 270 | "ADD INDEX {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . '_' . 271 | 'resource_link_pk_IDX (resource_link_pk ASC)'; 272 | $ok = $db->exec($sql) !== false; 273 | } 274 | } 275 | if ($ok && !tableExists($db, "{$prefix}item")) { 276 | // Adjust for different syntax of autoincrement columns 277 | $sql = "CREATE TABLE {$prefix}item (" . 278 | "item_pk int(11) NOT NULL AUTO_INCREMENT," . 279 | 'resource_link_pk int(11) NOT NULL, ' . 280 | 'item_title varchar(200) NOT NULL, ' . 281 | 'item_text text, ' . 282 | 'item_url varchar(200) DEFAULT NULL, ' . 283 | 'max_rating int(2) NOT NULL DEFAULT \'5\', ' . 284 | 'step int(1) NOT NULL DEFAULT \'1\', ' . 285 | 'visible tinyint(1) NOT NULL DEFAULT \'0\', ' . 286 | 'sequence int(3) NOT NULL DEFAULT \'0\', ' . 287 | 'created datetime NOT NULL, ' . 288 | 'updated datetime NOT NULL, ' . 289 | 'PRIMARY KEY (item_pk)' . 290 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 291 | $ok = $db->exec($sql) !== false; 292 | if ($ok) { 293 | $sql = "ALTER TABLE {$prefix}item " . 294 | "ADD CONSTRAINT {$prefix}item_" . 295 | DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . '_FK1 FOREIGN KEY (resource_link_pk) ' . 296 | "REFERENCES {$prefix}" . DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME . ' (resource_link_pk) ' . 297 | 'ON UPDATE CASCADE ' . 298 | 'ON DELETE CASCADE'; 299 | $ok = $db->exec($sql) !== false; 300 | } 301 | } 302 | 303 | if ($ok && !tableExists($db, "{$prefix}rating")) { 304 | $sql = "CREATE TABLE {$prefix}rating (" . 305 | 'item_pk int(11) NOT NULL, ' . 306 | 'user_pk int(11) NOT NULL, ' . 307 | 'rating decimal(10,2) NOT NULL, ' . 308 | 'PRIMARY KEY (item_pk, user_pk)' . 309 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8'; 310 | $ok = $db->exec($sql) !== false; 311 | if ($ok) { 312 | $sql = "ALTER TABLE {$prefix}rating " . 313 | "ADD CONSTRAINT {$prefix}rating_item_FK1 FOREIGN KEY (item_pk) " . 314 | "REFERENCES {$prefix}item (item_pk) " . 315 | 'ON UPDATE CASCADE ' . 316 | 'ON DELETE CASCADE'; 317 | $ok = $db->exec($sql) !== false; 318 | } 319 | } 320 | 321 | return $ok; 322 | } 323 | 324 | ?> 325 | -------------------------------------------------------------------------------- /src/images/cross.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/cross.gif -------------------------------------------------------------------------------- /src/images/delete.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/delete.gif -------------------------------------------------------------------------------- /src/images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/delete.png -------------------------------------------------------------------------------- /src/images/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/edit.png -------------------------------------------------------------------------------- /src/images/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/icon16.png -------------------------------------------------------------------------------- /src/images/icon50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/icon50.png -------------------------------------------------------------------------------- /src/images/icon50_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/icon50_disabled.png -------------------------------------------------------------------------------- /src/images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/loading.gif -------------------------------------------------------------------------------- /src/images/star.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/star.gif -------------------------------------------------------------------------------- /src/images/tick.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/celtic-project/Rating-PHP/4ae51c0e5abf2cce0bb6d3112a75e55583add42f/src/images/tick.gif -------------------------------------------------------------------------------- /src/index.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright SPV Software Products 14 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 15 | */ 16 | require_once('lib.php'); 17 | 18 | // Initialise session and database 19 | $db = null; 20 | $ok = init($db, true); 21 | // Initialise parameters 22 | $id = 0; 23 | $userList = false; 24 | $lineitemList = false; 25 | 26 | if ($ok) { 27 | $action = ''; 28 | // Check for item id and action parameters 29 | if (isset($_REQUEST['id'])) { 30 | $id = intval($_REQUEST['id']); 31 | } 32 | if (isset($_REQUEST['do'])) { 33 | $action = $_REQUEST['do']; 34 | } 35 | 36 | // Process add/update item action 37 | if ($action == 'add') { 38 | $updateItem = getItem($db, $_SESSION['resource_pk'], $id); 39 | $updateItem->item_title = $_POST['title']; 40 | $updateItem->item_text = $_POST['text']; 41 | $updateItem->item_url = $_POST['url']; 42 | $updateItem->max_rating = intval($_POST['max_rating']); 43 | $updateItem->step = intval($_POST['step']); 44 | $wasVisible = $updateItem->visible; 45 | $updateItem->visible = isset($_POST['visible']); 46 | // Ensure all required fields have been provided 47 | if (isset($_POST['id']) && isset($_POST['title']) && !empty($_POST['title'])) { 48 | $ok = true; 49 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 50 | $platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector); 51 | if (is_null($_SESSION['resource_pk'])) { 52 | $resourceLink = LTI\ResourceLink::fromPlatform($platform, $_SESSION['resource_id']); 53 | $ok = $resourceLink->save(); 54 | } else { 55 | $resourceLink = LTI\ResourceLink::fromRecordId($_SESSION['resource_pk'], $dataConnector); 56 | } 57 | if ($ok) { 58 | $_SESSION['resource_pk'] = $resourceLink->getRecordId(); 59 | $ok = saveItem($db, $_SESSION['resource_pk'], $updateItem); 60 | saveLineItem($resourceLink, $updateItem, empty($id)); 61 | if (!empty($id) && $updateItem->visible && !$wasVisible) { 62 | updateLineItemOutcomes($resourceLink, $updateItem); 63 | } 64 | } 65 | if ($ok) { 66 | $_SESSION['message'] = 'The item has been saved.'; 67 | if (!$_SESSION['isContentItem'] && ($updateItem->visible != $wasVisible)) { 68 | updateGradebook($db); 69 | } 70 | } else { 71 | $_SESSION['error_message'] = 'Unable to save the item; please check the data and try again.'; 72 | } 73 | header('Location: ./'); 74 | exit; 75 | } 76 | 77 | // Process delete item action 78 | } else if ($action == 'delete') { 79 | $updateItem = getItem($db, $_SESSION['resource_pk'], $id); 80 | $wasVisible = $updateItem->visible; 81 | if (deleteItem($db, $_SESSION['resource_pk'], $id)) { 82 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 83 | $resourceLink = LTI\ResourceLink::fromRecordId($_SESSION['resource_pk'], $dataConnector); 84 | if ($resourceLink->hasLineItemService()) { 85 | $lineItems = $resourceLink->getLineItems(strval($id)); 86 | if (!empty($lineItems)) { 87 | $lineItems[0]->delete(); 88 | } 89 | } 90 | $_SESSION['message'] = 'The item has been deleted.'; 91 | if (!$_SESSION['isContentItem'] && $wasVisible) { 92 | updateGradebook($db); 93 | } 94 | } else { 95 | $_SESSION['error_message'] = 'Unable to delete the item; please try again.'; 96 | } 97 | header('Location: ./'); 98 | exit; 99 | 100 | // Process content-item save action 101 | } else if ($action == 'saveci') { 102 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 103 | $platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector); 104 | // Pass on preference for overlay, popup, iframe, frame options in that order if any of these is offered 105 | $placement = null; 106 | $documentTarget = ''; 107 | if (in_array('overlay', $_SESSION['document_targets'])) { 108 | $documentTarget = 'overlay'; 109 | } else if (in_array('popup', $_SESSION['document_targets'])) { 110 | $documentTarget = 'popup'; 111 | } else if (in_array('iframe', $_SESSION['document_targets'])) { 112 | $documentTarget = 'iframe'; 113 | } else if (in_array('frame', $_SESSION['document_targets'])) { 114 | $documentTarget = 'frame'; 115 | } 116 | if (!empty($documentTarget)) { 117 | $placement = new Content\Placement($documentTarget); 118 | } 119 | $item = new Content\LtiLinkItem($placement); 120 | $item->setMediaType(Content\Item::LTI_LINK_MEDIA_TYPE); 121 | $item->setTitle($_SESSION['title']); 122 | $item->setText($_SESSION['text']); 123 | $item->setIcon(new Content\Image(getAppUrl() . 'images/icon50.png', 50, 50)); 124 | $item->addCustom('content_item_id', $_SESSION['resource_id']); 125 | if (strpos($platform->consumerVersion, 'canvas') === 0) { 126 | $item->setUrl(getAppUrl() . 'connect.php'); 127 | } 128 | $formParams['content_items'] = Content\Item::toJson($item, $_SESSION['lti_version']); 129 | if (!is_null($_SESSION['data'])) { 130 | $formParams['data'] = $_SESSION['data']; 131 | } 132 | LTI\Tool::$defaultTool->platform = $platform; 133 | $formParams = LTI\Tool::$defaultTool->signParameters($_SESSION['return_url'], 'ContentItemSelection', 134 | $_SESSION['lti_version'], $formParams); 135 | $page = LTI\Util::sendForm($_SESSION['return_url'], $formParams); 136 | echo $page; 137 | exit; 138 | 139 | // Process content-item cancel action 140 | } else if ($action == 'cancelci') { 141 | 142 | deleteAllItems($db, $_SESSION['resource_pk']); 143 | 144 | $formParams = array(); 145 | if (!is_null($_SESSION['data'])) { 146 | $formParams['data'] = $_SESSION['data']; 147 | } 148 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 149 | LTI\Tool::$defaultTool->platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector); 150 | $formParams = LTI\Tool::$defaultTool->signParameters($_SESSION['return_url'], 'ContentItemSelection', 151 | $_SESSION['lti_version'], $formParams); 152 | $page = LTI\Util::sendForm($_SESSION['return_url'], $formParams); 153 | echo $page; 154 | exit; 155 | 156 | // Process reorder item action 157 | } else if (($action == 'reorder') && (isset($_GET['seq']))) { 158 | if (reorderItem($db, $_SESSION['resource_pk'], intval($_GET['id']), intval($_GET['seq']))) { 159 | $_SESSION['message'] = 'The item has been moved.'; 160 | } else { 161 | $_SESSION['error_message'] = 'Unable to move the item; please try again.'; 162 | } 163 | header('Location: ./'); 164 | exit; 165 | } else if (isset($_POST['userlist'])) { 166 | $userList = true; 167 | } else if (isset($_POST['lineitemlist'])) { 168 | $lineitemList = true; 169 | } 170 | 171 | // Initialise an empty item instance 172 | $updateItem = new Item(); 173 | 174 | // Fetch a list of existing items for the resource link 175 | if (isset($_SESSION['resource_pk'])) { 176 | $items = getItems($db, $_SESSION['resource_pk']); 177 | } else { 178 | $items = array(); 179 | } 180 | 181 | if ($_SESSION['isStudent']) { 182 | // Fetch a list of ratings for items for the resource link for the student 183 | $userRated = getUserRated($db, $_SESSION['resource_pk'], $_SESSION['user_pk']); 184 | } 185 | } 186 | 187 | $here = function($val) { 188 | return $val; 189 | }; 190 | 191 | // Page header 192 | $page = <<< EOD 193 | 194 | 195 | 196 | 197 | 198 | {$here(APP_NAME)} 199 | 200 | 201 | 202 | 203 | 204 | 248 | 249 | 250 | 251 | 252 | EOD; 253 | 254 | // Check for any messages to be displayed 255 | if (isset($_SESSION['error_message'])) { 256 | $page .= <<< EOD 257 |

ERROR: {$_SESSION['error_message']}

258 | 259 | EOD; 260 | unset($_SESSION['error_message']); 261 | } 262 | 263 | if (isset($_SESSION['message'])) { 264 | $page .= <<< EOD 265 |

{$_SESSION['message']}

266 | 267 | EOD; 268 | unset($_SESSION['message']); 269 | } 270 | 271 | // Display table of existing platform records 272 | if ($ok) { 273 | 274 | if (count($items) <= 0) { 275 | $page .= <<< EOD 276 |

No items have been added yet.

277 | 278 | EOD; 279 | } else { 280 | $page .= <<< EOD 281 | 282 | 283 | 284 | EOD; 285 | $row = 0; 286 | foreach ($items as $item) { 287 | if (!$_SESSION['isStudent'] || $item->visible) { 288 | $row++; 289 | if (!empty($id) && ($id == $item->item_pk)) { 290 | $updateItem = $item; 291 | } 292 | if (!$item->visible) { 293 | $trClass = 'notvisible'; 294 | $row--; 295 | } else if (($row % 2) == 1) { 296 | $trClass = 'oddrow'; 297 | } else { 298 | $trClass = 'evenrow'; 299 | } 300 | if (isset($item->item_url)) { 301 | $title = '' . $item->item_title . ''; 302 | } else { 303 | $title = $item->item_title; 304 | } 305 | if (!$item->visible) { 306 | $title .= ' [hidden]'; 307 | } 308 | if (!empty($item->item_text)) { 309 | $text = "
\n{$item->item_text}"; 310 | } else { 311 | $text = ''; 312 | } 313 | $step = 1.0 / $item->step; 314 | $value = '0'; 315 | $readonly = 'true'; 316 | if ($_SESSION['isStudent'] && !array_key_exists(strval($item->item_pk), $userRated)) { 317 | $readonly = 'false'; 318 | } else if ($item->num_ratings > 0) { 319 | $value = floatToStr($item->tot_ratings / $item->num_ratings); 320 | } 321 | $page .= <<< EOD 322 | 323 | 324 | 325 | 326 | EOD; 327 | if (!$_SESSION['isStudent']) { 328 | $page .= <<< EOD 329 | 347 | 350 | 351 | EOD; 352 | } 353 | $page .= <<< EOD 354 | 355 | 356 | EOD; 357 | } 358 | } 359 | $page .= <<< EOD 360 | 361 |
{$title}{$text}
330 | 346 | 348 | Edit item Delete item 349 |
362 | 363 | EOD; 364 | } 365 | } 366 | 367 | // Display form for adding/editing an item 368 | if ($ok && !$_SESSION['isStudent'] && ($_SESSION['isContentItem'] || ($_SESSION['resource_pk'] === $_SESSION['user_resource_pk']))) { 369 | if (isset($updateItem->item_pk)) { 370 | $mode = 'Update'; 371 | } else { 372 | $mode = 'Add new'; 373 | } 374 | $title = ratingHtmlEntities($updateItem->item_title); 375 | $url = ratingHtmlEntities($updateItem->item_url); 376 | $text = ratingHtmlEntities($updateItem->item_text); 377 | if ($updateItem->visible) { 378 | $checked = ' checked="checked"'; 379 | } else { 380 | $checked = ''; 381 | } 382 | $page .= <<< EOD 383 | 384 |

{$mode} item

385 | 386 | EOD; 387 | if (!$_SESSION['isContentItem']) { 388 | $page .= <<< EOD 389 | 390 |
391 |
392 | New share key

393 | Life: 
404 | Auto approve? 

405 | 406 |
407 |
408 | 409 | EOD; 410 | } 411 | $page .= <<< EOD 412 |
413 |
414 | Title:* 
415 | URL: 
416 | Description: 
417 | Visible? 
418 | Maximum rating:* 
446 | Rating step:* 
451 |
452 | 453 | 454 | * = required field  455 | 456 | EOD; 457 | 458 | if (isset($updateItem->item_pk)) { 459 | $page .= <<< EOD 460 |   461 | 462 | EOD; 463 | } 464 | $page .= <<< EOD 465 |
466 | 467 | EOD; 468 | if ($_SESSION['isContentItem'] && !isset($updateItem->item_pk)) { 469 | $disabled = ''; 470 | if (count($items) <= 0) { 471 | $disabled = ' disabled="disabled"'; 472 | } 473 | $page .= <<< EOD 474 |

475 |
476 | 477 | 478 |

479 | 480 | EOD; 481 | } 482 | $page .= <<< EOD 483 |
484 | 485 | EOD; 486 | 487 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 488 | $resourceLink = ResourceLink::fromRecordId($_SESSION['resource_pk'], $dataConnector); 489 | $shares = $resourceLink->getShares(); 490 | if (count($shares) > 0) { 491 | $page .= <<< EOD 492 | 493 |

Shares

494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | EOD; 507 | $i = 0; 508 | foreach ($shares as $share) { 509 | $i++; 510 | if ($share->approved) { 511 | $shareApproved = 'tick'; 512 | $shareApproved_alt = 'Approved'; 513 | $action = 'Suspend'; 514 | } else { 515 | $shareApproved = 'cross'; 516 | $shareApproved_alt = 'Not approved'; 517 | $action = 'Approve'; 518 | } 519 | $page .= <<< EOD 520 | 521 | 522 | 523 | 524 | 528 | 529 | 530 | EOD; 531 | } 532 | $page .= <<< EOD 533 | 534 |
SourceTitleApprovedActions
{$share->consumerName}{$share->title}{$shareApproved_alt} 525 | 526 | 527 |
535 | 536 | EOD; 537 | } 538 | 539 | $page .= <<< EOD 540 |

Sample service requests

541 | 542 |
543 | 544 |

Users

545 | 546 | EOD; 547 | if ($resourceLink->hasMembershipsService()) { 548 | if ($userList) { 549 | $members = $resourceLink->getMemberships(true); 550 | $page .= <<< EOD 551 |
552 | 553 |
554 | 555 |

Users

556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | EOD; 569 | $users = array(); 570 | if (!empty($members)) { 571 | foreach ($members as $member) { 572 | $users["{$member->lastname}, {$member->firstname}"] = $member; 573 | } 574 | ksort($users); 575 | foreach ($users as $name => $user) { 576 | if ($user->isLearner()) { 577 | $img = 'tick.gif'; 578 | $ratings = count(getUserRated($db, $_SESSION['resource_pk'], $user->getRecordId())); 579 | } else { 580 | $img = 'cross.gif'; 581 | $ratings = 'NA'; 582 | } 583 | $page .= <<< EOD 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | EOD; 592 | } 593 | } 594 | $page .= <<< EOD 595 | 596 |
IDNameLearner?Ratings
{$user->ltiUserId}{$name}{$ratings}
597 | 598 | EOD; 599 | if (!empty($resourceLink->groupSets)) { 600 | $page .= <<< EOD 601 |

Group sets

602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | EOD; 613 | $groupSets = array(); 614 | foreach ($resourceLink->groupSets as $groupSetId => $groupSet) { 615 | $groupSets[$groupSet['title']] = $groupSet; 616 | } 617 | ksort($groupSets); 618 | foreach ($groupSets as $title => $groupSet) { 619 | $page .= <<< EOD 620 | 621 | 622 | 633 | 634 | 635 | EOD; 636 | } 637 | $page .= <<< EOD 638 | 639 |
NameGroups
{$title} 623 | 624 | EOD; 625 | foreach ($groupSet['groups'] as $groupId) { 626 | $page .= <<< EOD 627 | {$resourceLink->groups[$groupId]['title']}
628 | 629 | EOD; 630 | } 631 | $page .= <<< EOD 632 |
640 | 641 | EOD; 642 | } else { 643 | $page .= <<< EOD 644 |

645 | Your course does not appear to offer the ability to access a list of groups, or there are no group sets available. 646 |

647 | 648 | EOD; 649 | } 650 | } else { 651 | $page .= <<< EOD 652 |
653 | Your course appears to offer the ability to access a list of users. 654 |
655 | 656 | EOD; 657 | } 658 | } else if (!$_SESSION['isContentItem']) { 659 | $page .= <<< EOD 660 | Your course does not appear to offer the ability to access a list of users. 661 | 662 | EOD; 663 | } 664 | $page .= <<< EOD 665 |
666 | 667 |
668 | 669 |

Line Items

670 | 671 | EOD; 672 | if ($resourceLink->hasLineItemService()) { 673 | if ($lineitemList) { 674 | $lineitems = $resourceLink->getLineItems(); 675 | $page .= <<< EOD 676 |
677 | 678 |
679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | EOD; 693 | $sortedlineitems = array(); 694 | if (!empty($lineitems)) { 695 | foreach ($lineitems as $lineitem) { 696 | $sortedlineitems[$lineitem->label] = $lineitem; 697 | } 698 | ksort($sortedlineitems); 699 | foreach ($sortedlineitems as $label => $lineitem) { 700 | $page .= <<< EOD 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | EOD; 710 | } 711 | } 712 | $page .= <<< EOD 713 | 714 |
LabelPoints possibleResource Link IDResource IDTag
{$lineitem->label}$lineitem->pointsPossible{$lineitem->ltiResourceLinkId}{$lineitem->resourceId}{$lineitem->tag}
715 | 716 | EOD; 717 | } else { 718 | $page .= <<< EOD 719 |
720 | Your course appears to offer the ability to access a list of line items. 721 |
722 | 723 | EOD; 724 | } 725 | } else if (!$_SESSION['isContentItem']) { 726 | $page .= <<< EOD 727 | Your course does not appear to offer the ability to access a list of line items. 728 | 729 | EOD; 730 | } 731 | $page .= <<< EOD 732 |
733 | 734 | EOD; 735 | } 736 | 737 | // Page footer 738 | $page .= pageFooter(); 739 | $page .= <<< EOD 740 | 741 | 742 | 743 | EOD; 744 | 745 | // Display page 746 | echo $page; 747 | ?> 748 | -------------------------------------------------------------------------------- /src/js/jquery.rateit.min.js: -------------------------------------------------------------------------------- 1 | /*! RateIt | v1.1.5 / 03/10/2021 2 | https://github.com/gjunge/rateit.js | Twitter: @gjunge 3 | */ 4 | !function(M){function I(e){var t=e.originalEvent.changedTouches[0],a="";switch(e.type){case"touchmove":a="mousemove";break;case"touchend":a="mouseup";break;default:return}var i=document.createEvent("MouseEvent");i.initMouseEvent(a,!0,!0,window,1,t.screenX,t.screenY,t.clientX,t.clientY,!1,!1,!1,!1,0,null),t.target.dispatchEvent(i),e.preventDefault()}M.rateit={aria:{resetLabel:"reset rating",ratingLabel:"rating"}},M.fn.rateit=function(w,N){var y=1,C={},k="init",E=function(e){return e.charAt(0).toUpperCase()+e.substr(1)};if(0===this.length)return this;var e=typeof w;if("object"==e||null==w)C=M.extend({},M.fn.rateit.defaults,w);else{if("string"==e&&"reset"!==w&&void 0===N)return this.data("rateit"+E(w));"string"==e&&(k="setvalue")}return this.each(function(){var r=M(this),n=function(e,t){if(null!=t){var a="aria-value"+("value"==e?"now":e),i=r.find(".rateit-range");null!=i.attr(a)&&i.attr(a,t)}return e="rateit"+E(e),r.data.apply(r,arguments)};if("reset"==w){var e=n("init");for(var t in e)r.data(t,e[t]);if(n("backingfld"))"SELECT"==(a=M(n("backingfld")))[0].nodeName&&"index"===a[0].getAttribute("data-rateit-valuesrc")?a.prop("selectedIndex",n("value")):a.val(n("value")),a.trigger("change"),a[0].min&&(a[0].min=n("min")),a[0].max&&(a[0].max=n("max")),a[0].step&&(a[0].step=n("step"));r.trigger("reset")}r.hasClass("rateit")||r.addClass("rateit");var i="rtl"!=r.css("direction");if("setvalue"==k){if(!n("init"))throw"Can't set value before init";if("readonly"!=w||1!=N||n("readonly")||(r.find(".rateit-range").off(),n("wired",!1)),"value"==w&&(N=null==N?n("min"):Math.max(n("min"),Math.min(n("max"),N))),n("backingfld"))"SELECT"==(a=M(n("backingfld")))[0].nodeName&&"index"===a[0].getAttribute("data-rateit-valuesrc")?"value"==w&&a.prop("selectedIndex",N):"value"==w&&a.val(N),"min"==w&&a[0].min&&(a[0].min=N),"max"==w&&a[0].max&&(a[0].max=N),"step"==w&&a[0].step&&(a[0].step=N);n(w,N)}if(!n("init")){var a;if(n("mode",n("mode")||C.mode),n("icon",n("icon")||C.icon),n("min",isNaN(n("min"))?C.min:n("min")),n("max",isNaN(n("max"))?C.max:n("max")),n("step",n("step")||C.step),n("readonly",void 0!==n("readonly")?n("readonly"):C.readonly),n("resetable",void 0!==n("resetable")?n("resetable"):C.resetable),n("backingfld",n("backingfld")||C.backingfld),n("starwidth",n("starwidth")||C.starwidth),n("starheight",n("starheight")||C.starheight),n("value",Math.max(n("min"),Math.min(n("max"),isNaN(n("value"))?isNaN(C.value)?C.min:C.value:n("value")))),n("ispreset",void 0!==n("ispreset")?n("ispreset"):C.ispreset),n("backingfld"))if(((a=M(n("backingfld")).hide()).attr("disabled")||a.attr("readonly"))&&n("readonly",!0),"INPUT"==a[0].nodeName&&("range"!=a[0].type&&"text"!=a[0].type||(n("min",parseInt(a.attr("min"))||n("min")),n("max",parseInt(a.attr("max"))||n("max")),n("step",parseInt(a.attr("step"))||n("step")))),"SELECT"==a[0].nodeName&&1<{{element}} id="rateit-range-{{index}}" class="rateit-range"'+(1==n("readonly")?"":' tabindex="0"')+' role="slider" aria-label="'+M.rateit.aria.ratingLabel+'" aria-owns="rateit-reset-{{index}}" aria-valuemin="'+n("min")+'" aria-valuemax="'+n("max")+'" aria-valuenow="'+n("value")+'"><{{element}} class="rateit-empty"><{{element}} class="rateit-selected"><{{element}} class="rateit-hover">';r.append(l.replace(/{{index}}/gi,y).replace(/{{element}}/gi,d)),i||(r.find(".rateit-reset").css("float","right"),r.find(".rateit-selected").addClass("rateit-selected-rtl"),r.find(".rateit-hover").addClass("rateit-hover-rtl")),"font"==n("mode")?r.addClass("rateit-font").removeClass("rateit-bg"):r.addClass("rateit-bg").removeClass("rateit-font"),n("init",JSON.parse(JSON.stringify(r.data())))}var o="font"==n("mode");o||r.find(".rateit-selected, .rateit-hover").height(n("starheight"));var u=r.find(".rateit-range");if(o){for(var m=n("icon"),v=n("max")-n("min"),h="",c=0;c *").text(h),n("starwidth",u.width()/(n("max")-n("min")))}else u.width(n("starwidth")*(n("max")-n("min"))).height(n("starheight"));var g="rateit-preset"+(i?"":"-rtl");if(n("ispreset")?r.find(".rateit-selected").addClass(g):r.find(".rateit-selected").removeClass(g),null!=n("value")){var f=(n("value")-n("min"))*n("starwidth");r.find(".rateit-selected").width(f)}var p=r.find(".rateit-reset");!0!==p.data("wired")&&p.on("click",function(e){e.preventDefault(),p.trigger("blur");var t=M.Event("beforereset");if(r.trigger(t),t.isDefaultPrevented())return!1;r.rateit("value",null),r.trigger("reset")}).data("wired",!0);var b=function(e,t){var a=(t.changedTouches?t.changedTouches[0].pageX:t.pageX)-M(e).offset().left;return i||(a=u.width()-a),a>u.width()&&(a=u.width()),a<0&&(a=0),f=Math.ceil(a/n("starwidth")*(1/n("step")))},x=function(e){var t=M.Event("beforerated");return r.trigger(t,[e]),!t.isDefaultPrevented()&&(n("value",e),n("backingfld")&&("SELECT"==a[0].nodeName&&"index"===a[0].getAttribute("data-rateit-valuesrc")?M(n("backingfld")).prop("selectedIndex",e).trigger("change"):M(n("backingfld")).val(e).trigger("change")),n("ispreset")&&(u.find(".rateit-selected").removeClass(g),n("ispreset",!1)),u.find(".rateit-hover").hide(),u.find(".rateit-selected").width(e*n("starwidth")-n("min")*n("starwidth")).show(),r.trigger("hover",[null]).trigger("over",[null]).trigger("rated",[e]),!0)};n("readonly")?p.hide():(n("resetable")||p.hide(),n("wired")||(u.on("touchmove touchend",I),u.on("mousemove",function(e){!function(e){var t=e*n("starwidth")*n("step"),a=u.find(".rateit-hover");if(a.data("width")!=t){u.find(".rateit-selected").hide(),a.width(t).show().data("width",t);var i=[e*n("step")+n("min")];r.trigger("hover",i).trigger("over",i)}}(b(this,e))}),u.on("mouseleave",function(e){u.find(".rateit-hover").hide().width(0).data("width",""),r.trigger("hover",[null]).trigger("over",[null]),u.find(".rateit-selected").show()}),u.on("mouseup",function(e){var t=b(this,e)*n("step")+n("min");x(t),u.trigger("blur")}),u.on("keyup",function(e){38!=e.which&&e.which!=(i?39:37)||x(Math.min(n("value")+n("step"),n("max"))),40!=e.which&&e.which!=(i?37:39)||x(Math.max(n("value")-n("step"),n("min")))}),n("wired",!0)),n("resetable")&&p.show()),u.attr("aria-readonly",n("readonly"))})},M.fn.rateit.defaults={min:0,max:5,step:.5,mode:"bg",icon:"★",starwidth:16,starheight:16,readonly:!1,resetable:!0,ispreset:!1},M(function(){M("div.rateit, span.rateit").rateit()})}(jQuery); 5 | //# sourceMappingURL=jquery.rateit.min.js.map 6 | -------------------------------------------------------------------------------- /src/js/jquery.rateit.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["jquery.rateit.js"],"names":["$","touchHandler","event","first","originalEvent","changedTouches","type","simulatedEvent","document","createEvent","initMouseEvent","window","screenX","screenY","clientX","clientY","target","dispatchEvent","preventDefault","rateit","aria","resetLabel","ratingLabel","fn","p1","p2","index","options","mode","capitaliseFirstLetter","string","charAt","toUpperCase","substr","this","length","tp1","extend","defaults","undefined","data","each","item","itemdata","key","value","ariakey","range","find","attr","apply","arguments","setup","prop","fld","nodeName","getAttribute","val","trigger","min","max","step","hasClass","addClass","ltr","css","off","Math","icon","isNaN","readonly","resetable","backingfld","starwidth","starheight","ispreset","hide","parseInt","Number","selectedOption","element","html","append","replace","removeClass","JSON","parse","stringify","isfont","height","stars","txt","i","text","width","presetclass","score","resetbtn","on","e","Event","isDefaultPrevented","calcRawScore","offsetx","pageX","offset","left","ceil","setSelection","show","w","h","setHover","which","jQuery"],"mappings":"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","file":"jquery.rateit.min.js","sourcesContent":["/*! RateIt | v1.1.5 / 03/10/2021\r\n https://github.com/gjunge/rateit.js | Twitter: @gjunge\r\n*/\r\n(function ($) {\r\n $.rateit = {\r\n aria: {\r\n resetLabel: 'reset rating',\r\n ratingLabel: 'rating'\r\n }\r\n };\r\n\r\n $.fn.rateit = function (p1, p2) {\r\n //quick way out.\r\n var index = 1;\r\n var options = {}; var mode = 'init';\r\n var capitaliseFirstLetter = function (string) {\r\n return string.charAt(0).toUpperCase() + string.substr(1);\r\n };\r\n\r\n if (this.length === 0) { return this; }\r\n\r\n\r\n var tp1 = typeof p1;\r\n if (tp1 == 'object' || p1 === undefined || p1 === null) {\r\n options = $.extend({}, $.fn.rateit.defaults, p1); //wants to init new rateit plugin(s).\r\n }\r\n else if (tp1 == 'string' && p1 !== 'reset' && p2 === undefined) {\r\n return this.data('rateit' + capitaliseFirstLetter(p1)); //wants to get a value.\r\n }\r\n else if (tp1 == 'string') {\r\n mode = 'setvalue';\r\n }\r\n\r\n return this.each(function () {\r\n var item = $(this);\r\n\r\n\r\n //shorten all the item.data('rateit-XXX'), will save space in closure compiler, will be like item.data('XXX') will become x('XXX')\r\n var itemdata = function (key, value) {\r\n\r\n if (value != null) {\r\n //update aria values\r\n var ariakey = 'aria-value' + ((key == 'value') ? 'now' : key);\r\n var range = item.find('.rateit-range');\r\n if (range.attr(ariakey) != undefined) {\r\n range.attr(ariakey, value);\r\n }\r\n\r\n }\r\n\r\n arguments[0] = 'rateit' + capitaliseFirstLetter(key);\r\n return item.data.apply(item, arguments); ////Fix for WI: 523\r\n };\r\n\r\n //handle programmatic reset\r\n if (p1 == 'reset') {\r\n var setup = itemdata('init'); //get initial value\r\n for (var prop in setup) {\r\n item.data(prop, setup[prop]);\r\n }\r\n\r\n if (itemdata('backingfld')) { //reset also backingfield\r\n var fld = $(itemdata('backingfld'));\r\n // If backing field is a select box with valuesrc option set to \"index\", reset its selectedIndex property; otherwise, reset its value.\r\n if (fld[0].nodeName == 'SELECT' && fld[0].getAttribute('data-rateit-valuesrc') === 'index') {\r\n fld.prop('selectedIndex', itemdata('value'));\r\n }\r\n else {\r\n fld.val(itemdata('value'));\r\n }\r\n fld.trigger('change');\r\n if (fld[0].min) { fld[0].min = itemdata('min'); }\r\n if (fld[0].max) { fld[0].max = itemdata('max'); }\r\n if (fld[0].step) { fld[0].step = itemdata('step'); }\r\n }\r\n item.trigger('reset');\r\n }\r\n\r\n //add the rate it class.\r\n if (!item.hasClass('rateit')) { item.addClass('rateit'); }\r\n\r\n var ltr = item.css('direction') != 'rtl';\r\n\r\n // set value mode\r\n if (mode == 'setvalue') {\r\n if (!itemdata('init')) { throw 'Can\\'t set value before init'; }\r\n\r\n\r\n //if readonly now and it wasn't readonly, remove the eventhandlers.\r\n if (p1 == 'readonly' && p2 == true && !itemdata('readonly')) {\r\n item.find('.rateit-range').off();\r\n itemdata('wired', false);\r\n }\r\n //when we receive a null value, reset the score to its min value.\r\n if (p1 == 'value') {\r\n p2 = (p2 == null) ? itemdata('min') : Math.max(itemdata('min'), Math.min(itemdata('max'), p2));\r\n }\r\n if (itemdata('backingfld')) {\r\n //if we have a backing field, check which fields we should update.\r\n //In case of input[type=range], although we did read its attributes even in browsers that don't support it (using fld.attr())\r\n //we only update it in browser that support it (&& fld[0].min only works in supporting browsers), not only does it save us from checking if it is range input type, it also is unnecessary.\r\n var fld = $(itemdata('backingfld'));\r\n // If backing field is a select box with valuesrc option set to \"index\", update its selectedIndex property; otherwise, update its value.\r\n if (fld[0].nodeName == 'SELECT' && fld[0].getAttribute('data-rateit-valuesrc') === 'index') {\r\n if (p1 == 'value') { fld.prop('selectedIndex', p2); }\r\n }\r\n else {\r\n if (p1 == 'value') { fld.val(p2); }\r\n }\r\n if (p1 == 'min' && fld[0].min) { fld[0].min = p2; }\r\n if (p1 == 'max' && fld[0].max) { fld[0].max = p2;}\r\n if (p1 == 'step' && fld[0].step) { fld[0].step = p2; }\r\n }\r\n\r\n itemdata(p1, p2);\r\n }\r\n\r\n\r\n //init rateit plugin\r\n if (!itemdata('init')) {\r\n\r\n //get our values, either from the data-* html5 attribute or from the options.\r\n itemdata('mode', itemdata('mode') || options.mode)\r\n itemdata('icon', itemdata('icon') || options.icon)\r\n itemdata('min', isNaN(itemdata('min')) ? options.min : itemdata('min'));\r\n itemdata('max', isNaN(itemdata('max')) ? options.max : itemdata('max'));\r\n itemdata('step', itemdata('step') || options.step);\r\n itemdata('readonly', itemdata('readonly') !== undefined ? itemdata('readonly') : options.readonly);\r\n itemdata('resetable', itemdata('resetable') !== undefined ? itemdata('resetable') : options.resetable);\r\n itemdata('backingfld', itemdata('backingfld') || options.backingfld);\r\n itemdata('starwidth', itemdata('starwidth') || options.starwidth);\r\n itemdata('starheight', itemdata('starheight') || options.starheight);\r\n itemdata('value', Math.max(itemdata('min'), Math.min(itemdata('max'), (!isNaN(itemdata('value')) ? itemdata('value') : (!isNaN(options.value) ? options.value : options.min)))));\r\n itemdata('ispreset', itemdata('ispreset') !== undefined ? itemdata('ispreset') : options.ispreset);\r\n //are we LTR or RTL?\r\n\r\n if (itemdata('backingfld')) {\r\n //if we have a backing field, hide it, override defaults if range or select.\r\n var fld = $(itemdata('backingfld')).hide();\r\n\r\n if (fld.attr('disabled') || fld.attr('readonly')) {\r\n itemdata('readonly', true); //http://rateit.codeplex.com/discussions/362055 , if a backing field is disabled or readonly at instantiation, make rateit readonly.\r\n }\r\n\r\n if (fld[0].nodeName == 'INPUT') {\r\n if (fld[0].type == 'range' || fld[0].type == 'text') { //in browsers not support the range type, it defaults to text\r\n\r\n itemdata('min', parseInt(fld.attr('min')) || itemdata('min')); //if we would have done fld[0].min it wouldn't have worked in browsers not supporting the range type.\r\n itemdata('max', parseInt(fld.attr('max')) || itemdata('max'));\r\n itemdata('step', parseInt(fld.attr('step')) || itemdata('step'));\r\n }\r\n }\r\n if (fld[0].nodeName == 'SELECT' && fld[0].options.length > 1) {\r\n // If backing field is a select box with valuesrc option set to \"index\", use the indexes of its options; otherwise, use the values.\r\n if (fld[0].getAttribute('data-rateit-valuesrc') === 'index') {\r\n itemdata('min', (!isNaN(itemdata('min')) ? itemdata('min') : Number(fld[0].options[0].index)));\r\n itemdata('max', Number(fld[0].options[fld[0].length - 1].index));\r\n itemdata('step', Number(fld[0].options[1].index) - Number(fld[0].options[0].index));\r\n }\r\n else {\r\n itemdata('min', (!isNaN(itemdata('min')) ? itemdata('min') : Number(fld[0].options[0].value)));\r\n itemdata('max', Number(fld[0].options[fld[0].length - 1].value));\r\n itemdata('step', Number(fld[0].options[1].value) - Number(fld[0].options[0].value));\r\n }\r\n //see if we have a option that as explicity been selected\r\n var selectedOption = fld.find('option[selected]');\r\n if (selectedOption.length == 1) {\r\n // If backing field is a select box with valuesrc option set to \"index\", use the index of selected option; otherwise, use the value.\r\n if (fld[0].getAttribute('data-rateit-valuesrc') === 'index') {\r\n itemdata('value', selectedOption[0].index);\r\n }\r\n else {\r\n itemdata('value', selectedOption.val());\r\n }\r\n }\r\n }\r\n else {\r\n //if it is not a select box, we can get's it's value using the val function.\r\n //If it is a selectbox, we always get a value (the first one of the list), even if it was not explicity set.\r\n itemdata('value', fld.val());\r\n }\r\n\r\n\r\n }\r\n\r\n\r\n\r\n //Create the necessary tags. For ARIA purposes we need to give the items an ID. So we use an internal index to create unique ids\r\n var element = item[0].nodeName == 'DIV' ? 'div' : 'span';\r\n index++;\r\n\r\n // tabindex=\"0\" gets only added in readonly mode. When keyboard tabbing, no focus is needed in readonly mode.\r\n var html = '<{{element}} id=\"rateit-range-{{index}}\" class=\"rateit-range\"' + (itemdata('readonly') == true ? '' : ' tabindex=\"0\"') + ' role=\"slider\" aria-label=\"' + $.rateit.aria.ratingLabel + '\" aria-owns=\"rateit-reset-{{index}}\" aria-valuemin=\"' + itemdata('min') + '\" aria-valuemax=\"' + itemdata('max') + '\" aria-valuenow=\"' + itemdata('value') + '\"><{{element}} class=\"rateit-empty\"><{{element}} class=\"rateit-selected\"><{{element}} class=\"rateit-hover\">';\r\n item.append(html.replace(/{{index}}/gi, index).replace(/{{element}}/gi, element));\r\n\r\n //if we are in RTL mode, we have to change the float of the \"reset button\"\r\n if (!ltr) {\r\n item.find('.rateit-reset').css('float', 'right');\r\n item.find('.rateit-selected').addClass('rateit-selected-rtl');\r\n item.find('.rateit-hover').addClass('rateit-hover-rtl');\r\n }\r\n\r\n if (itemdata('mode') == 'font') {\r\n item.addClass('rateit-font').removeClass('rateit-bg');\r\n }\r\n else {\r\n item.addClass('rateit-bg').removeClass('rateit-font');\r\n }\r\n\r\n itemdata('init', JSON.parse(JSON.stringify(item.data()))); //cheap way to create a clone\r\n }\r\n\r\n var isfont = itemdata('mode') == 'font';\r\n\r\n\r\n\r\n\r\n //resize the height of all elements,\r\n if (!isfont) {\r\n item.find('.rateit-selected, .rateit-hover').height(itemdata('starheight'));\r\n }\r\n\r\n\r\n var range = item.find('.rateit-range');\r\n if (isfont) {\r\n //fill the ranges with the icons\r\n var icon = itemdata('icon');\r\n var stars = itemdata('max') - itemdata('min');\r\n\r\n var txt = '';\r\n for(var i = 0; i< stars; i++){\r\n txt += icon;\r\n }\r\n\r\n range.find('> *').text(txt);\r\n\r\n\r\n itemdata('starwidth', range.width() / (itemdata('max') - itemdata('min')))\r\n }\r\n else {\r\n //set the range element to fit all the stars.\r\n range.width(itemdata('starwidth') * (itemdata('max') - itemdata('min'))).height(itemdata('starheight'));\r\n }\r\n\r\n\r\n //add/remove the preset class\r\n var presetclass = 'rateit-preset' + ((ltr) ? '' : '-rtl');\r\n if (itemdata('ispreset')) {\r\n item.find('.rateit-selected').addClass(presetclass);\r\n }\r\n else {\r\n item.find('.rateit-selected').removeClass(presetclass);\r\n }\r\n\r\n //set the value if we have it.\r\n if (itemdata('value') != null) {\r\n var score = (itemdata('value') - itemdata('min')) * itemdata('starwidth');\r\n item.find('.rateit-selected').width(score);\r\n }\r\n\r\n //setup the reset button\r\n var resetbtn = item.find('.rateit-reset');\r\n if (resetbtn.data('wired') !== true) {\r\n resetbtn.on('click', function (e) {\r\n e.preventDefault();\r\n\r\n resetbtn.trigger('blur');\r\n\r\n var event = $.Event('beforereset');\r\n item.trigger(event);\r\n if (event.isDefaultPrevented()) {\r\n return false;\r\n }\r\n\r\n item.rateit('value', null);\r\n item.trigger('reset');\r\n }).data('wired', true);\r\n\r\n }\r\n\r\n //this function calculates the score based on the current position of the mouse.\r\n var calcRawScore = function (element, event) {\r\n var pageX = (event.changedTouches) ? event.changedTouches[0].pageX : event.pageX;\r\n\r\n var offsetx = pageX - $(element).offset().left;\r\n if (!ltr) { offsetx = range.width() - offsetx };\r\n if (offsetx > range.width()) { offsetx = range.width(); }\r\n if (offsetx < 0) { offsetx = 0; }\r\n\r\n return score = Math.ceil(offsetx / itemdata('starwidth') * (1 / itemdata('step')));\r\n };\r\n\r\n //sets the hover element based on the score.\r\n var setHover = function (score) {\r\n var w = score * itemdata('starwidth') * itemdata('step');\r\n var h = range.find('.rateit-hover');\r\n if (h.data('width') != w) {\r\n range.find('.rateit-selected').hide();\r\n h.width(w).show().data('width', w);\r\n var data = [(score * itemdata('step')) + itemdata('min')];\r\n item.trigger('hover', data).trigger('over', data);\r\n }\r\n };\r\n\r\n var setSelection = function (value) {\r\n var event = $.Event('beforerated');\r\n item.trigger(event, [value]);\r\n if (event.isDefaultPrevented()) {\r\n return false;\r\n }\r\n\r\n itemdata('value', value);\r\n if (itemdata('backingfld')) {\r\n // If backing field is a select box with valuesrc option set to \"index\", update its selectedIndex property; otherwise, update its value.\r\n if (fld[0].nodeName == 'SELECT' && fld[0].getAttribute('data-rateit-valuesrc') === 'index') {\r\n $(itemdata('backingfld')).prop('selectedIndex', value).trigger('change');\r\n }\r\n else {\r\n $(itemdata('backingfld')).val(value).trigger('change');\r\n }\r\n }\r\n if (itemdata('ispreset')) { //if it was a preset value, unset that.\r\n range.find('.rateit-selected').removeClass(presetclass);\r\n itemdata('ispreset', false);\r\n }\r\n range.find('.rateit-hover').hide();\r\n range.find('.rateit-selected').width(value * itemdata('starwidth') - (itemdata('min') * itemdata('starwidth'))).show();\r\n item.trigger('hover', [null]).trigger('over', [null]).trigger('rated', [value]);\r\n return true;\r\n };\r\n\r\n if (!itemdata('readonly')) {\r\n //if we are not read only, add all the events\r\n\r\n //if we have a reset button, set the event handler.\r\n if (!itemdata('resetable')) {\r\n resetbtn.hide();\r\n }\r\n\r\n //when the mouse goes over the range element, we set the \"hover\" stars.\r\n if (!itemdata('wired')) {\r\n range.on('touchmove touchend', touchHandler); //bind touch events\r\n range.on('mousemove', function (e) {\r\n var score = calcRawScore(this, e);\r\n setHover(score);\r\n });\r\n //when the mouse leaves the range, we have to hide the hover stars, and show the current value.\r\n range.on('mouseleave', function (e) {\r\n range.find('.rateit-hover').hide().width(0).data('width', '');\r\n item.trigger('hover', [null]).trigger('over', [null]);\r\n range.find('.rateit-selected').show();\r\n });\r\n //when we click on the range, we have to set the value, hide the hover.\r\n range.on('mouseup', function (e) {\r\n var score = calcRawScore(this, e);\r\n var value = (score * itemdata('step')) + itemdata('min');\r\n setSelection(value);\r\n range.trigger('blur');\r\n });\r\n\r\n //support key nav\r\n range.on('keyup', function (e) {\r\n if (e.which == 38 || e.which == (ltr ? 39 : 37)) {\r\n setSelection(Math.min(itemdata('value') + itemdata('step'), itemdata('max')));\r\n }\r\n if (e.which == 40 || e.which == (ltr ? 37 : 39)) {\r\n setSelection(Math.max(itemdata('value') - itemdata('step'), itemdata('min')));\r\n }\r\n });\r\n\r\n itemdata('wired', true);\r\n }\r\n if (itemdata('resetable')) {\r\n resetbtn.show();\r\n }\r\n }\r\n else {\r\n resetbtn.hide();\r\n }\r\n\r\n range.attr('aria-readonly', itemdata('readonly'));\r\n });\r\n };\r\n\r\n //touch converter http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript/\r\n function touchHandler(event) {\r\n\r\n var touches = event.originalEvent.changedTouches,\r\n first = touches[0],\r\n type = \"\";\r\n switch (event.type) {\r\n case \"touchmove\": type = \"mousemove\"; break;\r\n case \"touchend\": type = \"mouseup\"; break;\r\n default: return;\r\n }\r\n\r\n var simulatedEvent = document.createEvent(\"MouseEvent\");\r\n simulatedEvent.initMouseEvent(type, true, true, window, 1,\r\n first.screenX, first.screenY,\r\n first.clientX, first.clientY, false,\r\n false, false, false, 0/*left*/, null);\r\n\r\n first.target.dispatchEvent(simulatedEvent);\r\n event.preventDefault();\r\n };\r\n\r\n //some default values.\r\n $.fn.rateit.defaults = { min: 0, max: 5, step: 0.5, mode: 'bg', icon: '★', starwidth: 16, starheight: 16, readonly: false, resetable: true, ispreset: false };\r\n\r\n //invoke it on all .rateit elements. This could be removed if not wanted.\r\n $(function () { $('div.rateit, span.rateit').rateit(); });\r\n\r\n})(jQuery);\r\n"]} -------------------------------------------------------------------------------- /src/js/rating.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This page displays a list of items for a resource link. Students are able to rate 3 | * each item; staff may add, edit, re-order and delete items. 4 | * 5 | * @author Stephen P Vickers 6 | * @copyright SPV Software Products 7 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 8 | */ 9 | 10 | var http_request = false; 11 | var el_id; 12 | 13 | function getHTTPRequest() { 14 | http_request = false; 15 | if (window.XMLHttpRequest) { // Mozilla, Safari,... 16 | http_request = new XMLHttpRequest(); 17 | } else if (window.ActiveXObject) { // IE 18 | try { 19 | http_request = new ActiveXObject("Msxml2.XMLHTTP"); 20 | } catch (e) { 21 | try { 22 | http_request = new ActiveXObject("Microsoft.XMLHTTP"); 23 | } catch (e) { 24 | } 25 | } 26 | } 27 | } 28 | 29 | function doGenerateKey() { 30 | getHTTPRequest() 31 | if (http_request) { 32 | var url = 'share.php?do=generate'; 33 | var el = document.getElementById('life'); 34 | url += '&life=' + el.value; 35 | el = document.getElementById('auto_approve'); 36 | if (el.checked) { 37 | url += '&auto_approve=yes'; 38 | } 39 | http_request.onreadystatechange = alertGenerateKey; 40 | http_request.open('GET', url, true); 41 | http_request.send(null); 42 | } 43 | return false; 44 | } 45 | 46 | function alertGenerateKey() { 47 | if (http_request.readyState == 4) { 48 | if (http_request.status == 200) { 49 | var key = http_request.responseText; 50 | if (key.length > 0) { 51 | window.prompt('Send this share key string to the other instructor:', 'share_key=' + key); 52 | } else { 53 | alert('Sorry an error occurred in generating a new share key; please try again'); 54 | } 55 | } else { 56 | alert('Sorry unable to generate a new share key'); 57 | } 58 | } 59 | } 60 | 61 | function doApprove(id, action, rlid) { 62 | getHTTPRequest() 63 | if (http_request) { 64 | var url = 'share.php?do=' + escape(action) + '&rlid=' + escape(rlid); 65 | el_id = id; 66 | http_request.onreadystatechange = alertApprove; 67 | http_request.open('GET', url, true); 68 | http_request.send(null); 69 | } 70 | return false; 71 | } 72 | 73 | function alertApprove() { 74 | if (http_request.readyState == 4) { 75 | if (http_request.status == 200) { 76 | var button = document.getElementById('btn' + el_id); 77 | var img = document.getElementById('img' + el_id); 78 | if (button.value == 'Approve') { 79 | button.value = 'Suspend'; 80 | img.src = 'images/tick.gif'; 81 | } else { 82 | button.value = 'Approve'; 83 | img.src = 'images/cross.gif'; 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/jwks.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright SPV Software Products 10 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 11 | */ 12 | require_once('db.php'); 13 | 14 | $jwt = Jwt::getJwtClient(); 15 | $keys = $jwt::getJWKS(PRIVATE_KEY, SIGNATURE_METHOD, KID); 16 | 17 | header('Content-type: application/json'); 18 | echo json_encode($keys); 19 | ?> -------------------------------------------------------------------------------- /src/lib.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright SPV Software Products 13 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 14 | */ 15 | require_once('db.php'); 16 | require_once('rating_tp.php'); 17 | 18 | ### Application settings 19 | define('APP_NAME', 'Rating'); 20 | define('APP_VERSION', '5.0.0'); 21 | define('SESSION_NAME', 'php-rating'); 22 | 23 | LTI\ResourceLink::registerApiHook(LTI\ResourceLink::$MEMBERSHIPS_SERVICE_HOOK, 'moodle', 24 | 'ceLTIc\LTI\ApiHook\moodle\MoodleApiResourceLink'); 25 | LTI\Tool::registerApiHook(LTI\Tool::$USER_ID_HOOK, 'canvas', 'ceLTIc\LTI\ApiHook\canvas\CanvasApiTool'); 26 | LTI\ResourceLink::registerApiHook(LTI\ResourceLink::$MEMBERSHIPS_SERVICE_HOOK, 'canvas', 27 | 'ceLTIc\LTI\ApiHook\canvas\CanvasApiResourceLink'); 28 | 29 | ### 30 | ### Initialise application session and database connection 31 | ### 32 | 33 | function init(&$db, $checkSession = null, $currentLevel = 0) 34 | { 35 | $ok = true; 36 | 37 | // Check if path value passed by web server needs amending 38 | if (defined('REQUEST_URI_PREFIX') && !empty(REQUEST_URI_PREFIX)) { 39 | $_SERVER['REQUEST_URI'] = REQUEST_URI_PREFIX . $_SERVER['REQUEST_URI']; 40 | } 41 | 42 | // Set timezone 43 | if (!ini_get('date.timezone')) { 44 | date_default_timezone_set('UTC'); 45 | } 46 | 47 | // Set session cookie path 48 | ini_set('session.cookie_path', getAppPath($currentLevel)); 49 | 50 | // Set samesite value for cookie 51 | if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') { 52 | ini_set('session.cookie_samesite', 'none'); 53 | ini_set('session.cookie_secure', true); 54 | } 55 | 56 | // Open session 57 | session_name(SESSION_NAME); 58 | session_start(); 59 | 60 | // Set the default tool 61 | LTI\Tool::$defaultTool = new RatingTool(null); 62 | 63 | if (!is_null($checkSession) && $checkSession) { 64 | $ok = isset($_SESSION['consumer_pk']) && (isset($_SESSION['resource_pk']) || is_null($_SESSION['resource_pk'])) && 65 | isset($_SESSION['user_consumer_pk']) && (isset($_SESSION['user_pk']) || is_null($_SESSION['user_pk'])) && isset($_SESSION['isStudent']); 66 | } 67 | 68 | if (!$ok) { 69 | $_SESSION['error_message'] = 'Unable to open session.'; 70 | } else { 71 | // Open database connection 72 | $db = open_db(!$checkSession); 73 | $ok = $db !== false; 74 | if (!$ok) { 75 | if (!is_null($checkSession) && $checkSession) { 76 | // Display a more user-friendly error message to LTI users 77 | $_SESSION['error_message'] = 'Unable to open database.'; 78 | } 79 | } else if (!is_null($checkSession) && !$checkSession) { 80 | // Create database tables (if needed) 81 | $ok = init_db($db); // assumes a MySQL/SQLite database is being used 82 | if (!$ok) { 83 | $_SESSION['error_message'] = 'Unable to initialise database: \'' . $db->errorInfo()[2] . '\''; 84 | } 85 | } 86 | } 87 | 88 | return $ok; 89 | } 90 | 91 | ### 92 | ### Return the number of items to be rated for a specified resource link 93 | ### 94 | 95 | function getNumItems($db, $resourcePk) 96 | { 97 | $prefix = DB_TABLENAME_PREFIX; 98 | $sql = <<< EOD 99 | SELECT COUNT(i.item_pk) 100 | FROM {$prefix}item i 101 | WHERE (i.resource_link_pk = :resource_pk) 102 | EOD; 103 | 104 | $query = $db->prepare($sql); 105 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 106 | $query->execute(); 107 | 108 | $row = $query->fetch(PDO::FETCH_NUM); 109 | if ($row === false) { 110 | $num = 0; 111 | } else { 112 | $num = intval($row[0]); 113 | } 114 | 115 | return $num; 116 | } 117 | 118 | ### 119 | ### Return an array containing the items for a specified resource link 120 | ### 121 | 122 | function getItems($db, $resourcePk) 123 | { 124 | $prefix = DB_TABLENAME_PREFIX; 125 | $sql = <<< EOD 126 | SELECT i.item_pk, i.item_title, i.item_text, i.item_url, i.max_rating mr, i.step st, i.visible vis, i.sequence seq, 127 | i.created cr, i.updated upd, COUNT(r.user_pk) num, SUM(r.rating) total 128 | FROM {$prefix}item i LEFT OUTER JOIN {$prefix}rating r ON i.item_pk = r.item_pk 129 | WHERE (i.resource_link_pk = :resource_pk) 130 | GROUP BY i.item_pk, i.item_title, i.item_text, i.item_url, i.max_rating, i.step, i.visible, i.sequence, i.created, i.updated 131 | ORDER BY i.sequence 132 | EOD; 133 | 134 | $query = $db->prepare($sql); 135 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 136 | $query->execute(); 137 | 138 | $rows = $query->fetchAll(PDO::FETCH_CLASS, 'Item'); 139 | if ($rows === false) { 140 | $rows = array(); 141 | } 142 | 143 | return $rows; 144 | } 145 | 146 | ### 147 | ### Return an array of ratings made for items for a specified resource link by a specified user 148 | ### 149 | 150 | function getUserRated($db, $resourcePk, $userPk) 151 | { 152 | $prefix = DB_TABLENAME_PREFIX; 153 | $sql = <<< EOD 154 | SELECT r.item_pk, r.rating 155 | FROM {$prefix}item i INNER JOIN {$prefix}rating r ON i.item_pk = r.item_pk 156 | WHERE (i.resource_link_pk = :resource_pk) AND (r.user_pk = :user_pk) 157 | EOD; 158 | 159 | $query = $db->prepare($sql); 160 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 161 | $query->bindValue('user_pk', $userPk, PDO::PARAM_INT); 162 | $query->execute(); 163 | 164 | $rows = $query->fetchAll(PDO::FETCH_OBJ); 165 | $rated = array(); 166 | if ($rows !== false) { 167 | foreach ($rows as $row) { 168 | $rated[$row->item_pk] = $row->rating; 169 | } 170 | } 171 | 172 | return $rated; 173 | } 174 | 175 | ### 176 | ### Return details for a specific item for a specified resource link 177 | ### 178 | 179 | function getItem($db, $resourcePk, $itemPk) 180 | { 181 | $item = new Item(); 182 | 183 | if (!empty($itemPk)) { 184 | $prefix = DB_TABLENAME_PREFIX; 185 | $sql = <<< EOD 186 | SELECT i.item_pk, i.item_title, i.item_text, i.item_url, i.max_rating mr, i.step st, i.visible vis, i.sequence seq, i.created cr, i.updated upd 187 | FROM {$prefix}item i 188 | WHERE (i.resource_link_pk = :resource_pk) AND (i.item_pk = :item_pk) 189 | EOD; 190 | 191 | $query = $db->prepare($sql); 192 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 193 | $query->bindValue('item_pk', $itemPk, PDO::PARAM_INT); 194 | $query->setFetchMode(PDO::FETCH_CLASS, 'Item'); 195 | $query->execute(); 196 | 197 | $row = $query->fetch(); 198 | if ($row !== false) { 199 | $item = $row; 200 | } 201 | } 202 | 203 | return $item; 204 | } 205 | 206 | ### 207 | ### Save the details for an item for a specified resource link 208 | ### 209 | 210 | function saveItem($db, $resourcePk, $item) 211 | { 212 | $prefix = DB_TABLENAME_PREFIX; 213 | if (!isset($item->item_pk)) { 214 | $sql = <<< EOD 215 | INSERT INTO {$prefix}item (resource_link_pk, item_title, item_text, item_url, max_rating, step, visible, sequence, created, updated) 216 | VALUES (:resource_pk, :item_title, :item_text, :item_url, :max_rating, :step, :visible, :sequence, :created, :updated) 217 | EOD; 218 | } else { 219 | $sql = <<< EOD 220 | UPDATE {$prefix}item 221 | SET item_title = :item_title, item_text = :item_text, item_url = :item_url, max_rating = :max_rating, step = :step, visible = :visible, 222 | sequence = :sequence, updated = :updated 223 | WHERE (item_pk = :item_pk) AND (resource_link_pk = :resource_pk) 224 | EOD; 225 | } 226 | $query = $db->prepare($sql); 227 | $item->updated = new DateTime(); 228 | if (!isset($item->item_pk)) { 229 | $item->created = $item->updated; 230 | $item->sequence = getNumItems($db, $resourcePk) + 1; 231 | $query->bindValue('created', $item->created->format('Y-m-d H:i:s'), PDO::PARAM_STR); 232 | } else { 233 | $query->bindValue('item_pk', $item->item_pk, PDO::PARAM_INT); 234 | } 235 | $query->bindValue('item_title', $item->item_title, PDO::PARAM_STR); 236 | $query->bindValue('item_text', $item->item_text, PDO::PARAM_STR); 237 | $query->bindValue('item_url', $item->item_url, PDO::PARAM_STR); 238 | $query->bindValue('max_rating', $item->max_rating, PDO::PARAM_INT); 239 | $query->bindValue('step', $item->step, PDO::PARAM_INT); 240 | $query->bindValue('visible', $item->visible, PDO::PARAM_INT); 241 | $query->bindValue('sequence', $item->sequence, PDO::PARAM_INT); 242 | $query->bindValue('updated', $item->updated->format('Y-m-d H:i:s'), PDO::PARAM_STR); 243 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 244 | 245 | $ok = $query->execute(); 246 | 247 | if ($ok && !isset($item->item_pk)) { 248 | $item->item_pk = intval($db->lastInsertId()); 249 | } 250 | 251 | return $ok; 252 | } 253 | 254 | ### 255 | ### Delete the ratings for an item 256 | ### 257 | 258 | function deleteRatings($db, $itemPk) 259 | { 260 | $prefix = DB_TABLENAME_PREFIX; 261 | $sql = <<< EOD 262 | DELETE FROM {$prefix}rating 263 | WHERE item_pk = :item_pk 264 | EOD; 265 | 266 | $query = $db->prepare($sql); 267 | $query->bindValue('item_pk', $itemPk, PDO::PARAM_INT); 268 | $query->execute(); 269 | } 270 | 271 | ### 272 | ### Delete a specific item for a specified resource link including any related ratings 273 | ### 274 | 275 | function deleteItem($db, $resourcePk, $itemPk) 276 | { 277 | // Update order for other items for the same resource link 278 | reorderItem($db, $resourcePk, $itemPk, 0); 279 | 280 | // Delete any ratings 281 | deleteRatings($db, $itemPk); 282 | 283 | // Delete the item 284 | $prefix = DB_TABLENAME_PREFIX; 285 | $sql = <<< EOD 286 | DELETE FROM {$prefix}item 287 | WHERE (item_pk = :item_pk) AND (resource_link_pk = :resource_pk) 288 | EOD; 289 | 290 | $query = $db->prepare($sql); 291 | $query->bindValue('item_pk', $itemPk, PDO::PARAM_INT); 292 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_STR); 293 | $ok = $query->execute(); 294 | 295 | return $ok; 296 | } 297 | 298 | ### 299 | ### Change the position of an item in the list displayed for the resource link 300 | ### 301 | 302 | function reorderItem($db, $resourcePk, $itemPk, $new_pos) 303 | { 304 | $item = getItem($db, $resourcePk, $itemPk); 305 | 306 | $ok = !empty($item->item_pk); 307 | if ($ok) { 308 | $old_pos = $item->sequence; 309 | $ok = ($old_pos != $new_pos); 310 | } 311 | if ($ok) { 312 | $prefix = DB_TABLENAME_PREFIX; 313 | if ($new_pos <= 0) { 314 | $sql = <<< EOD 315 | UPDATE {$prefix}item 316 | SET sequence = sequence - 1 317 | WHERE (resource_link_pk = :resource_pk) AND (sequence > :old_pos) 318 | EOD; 319 | } else if ($old_pos < $new_pos) { 320 | $sql = <<< EOD 321 | UPDATE {$prefix}item 322 | SET sequence = sequence - 1 323 | WHERE (resource_link_pk = :resource_pk) AND (sequence > :old_pos) AND (sequence <= :new_pos) 324 | EOD; 325 | } else { 326 | $sql = <<< EOD 327 | UPDATE {$prefix}item 328 | SET sequence = sequence + 1 329 | WHERE (resource_link_pk = :resource_pk) AND (sequence < :old_pos) AND (sequence >= :new_pos) 330 | EOD; 331 | } 332 | 333 | $query = $db->prepare($sql); 334 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 335 | $query->bindValue('old_pos', $old_pos, PDO::PARAM_INT); 336 | if ($new_pos > 0) { 337 | $query->bindValue('new_pos', $new_pos, PDO::PARAM_INT); 338 | } 339 | 340 | $ok = $query->execute(); 341 | 342 | if ($ok && ($new_pos > 0)) { 343 | $item->sequence = $new_pos; 344 | $ok = saveItem($db, $resourcePk, $item); 345 | } 346 | } 347 | 348 | return $ok; 349 | } 350 | 351 | ### 352 | ### Delete all the ratings for an resource link 353 | ### 354 | 355 | function deleteAllRatings($db, $resourcePk) 356 | { 357 | $prefix = DB_TABLENAME_PREFIX; 358 | $sql = <<< EOD 359 | DELETE FROM {$prefix}rating 360 | WHERE resource_link_pk = :resource_pk 361 | EOD; 362 | 363 | $query = $db->prepare($sql); 364 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_INT); 365 | $query->execute(); 366 | } 367 | 368 | ### 369 | ### Delete all items for a specified resource link including any related ratings 370 | ### 371 | 372 | function deleteAllItems($db, $resourcePk) 373 | { 374 | // Delete any ratings 375 | deleteAllRatings($db, $resourcePk); 376 | 377 | // Delete the items 378 | $prefix = DB_TABLENAME_PREFIX; 379 | $sql = <<< EOD 380 | DELETE FROM {$prefix}item 381 | WHERE (resource_link_pk = :resource_pk) 382 | EOD; 383 | 384 | $query = $db->prepare($sql); 385 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_STR); 386 | $ok = $query->execute(); 387 | 388 | return $ok; 389 | } 390 | 391 | ### 392 | ### Save the rating for an item for a specified user 393 | ### 394 | 395 | function saveRating($db, $userPk, $itemPk, $rating) 396 | { 397 | $prefix = DB_TABLENAME_PREFIX; 398 | $sql = <<< EOD 399 | INSERT INTO {$prefix}rating (item_pk, user_pk, rating) 400 | VALUES (:item_pk, :user_pk, :rating) 401 | EOD; 402 | 403 | $query = $db->prepare($sql); 404 | $query->bindValue('item_pk', $itemPk, PDO::PARAM_INT); 405 | $query->bindValue('user_pk', $userPk, PDO::PARAM_INT); 406 | $query->bindValue('rating', $rating); 407 | 408 | $ok = $query->execute(); 409 | 410 | return $ok; 411 | } 412 | 413 | ### 414 | ### Create/update the line item for this item 415 | ### 416 | 417 | function saveLineItem($resourceLink, $item, $isNew) 418 | { 419 | if ($resourceLink->hasLineItemService()) { 420 | $resourceId = strval($item->item_pk); 421 | $label = "Rating: {$item->item_title}"; 422 | $tag = 'Rating'; 423 | $pointsPossible = $item->max_rating; 424 | $visible = $item->visible; 425 | if (!$isNew) { 426 | $lineItems = $resourceLink->getLineItems($resourceId); 427 | $isNew = empty($lineItems); 428 | } 429 | if (!$isNew) { 430 | $lineItem = reset($lineItems); 431 | if (!$visible) { 432 | $lineItem->delete(); 433 | } else if (($lineItem->label !== $label) || ($lineItem->tag !== $tag) || ($lineItem->pointsPossible !== $pointsPossible)) { 434 | $lineItem->label = $label; 435 | $lineItem->tag = $tag; 436 | $lineItem->pointsPossible = $pointsPossible; 437 | $lineItem->save(); 438 | } 439 | } else if ($visible) { 440 | $lineItem = new LTI\LineItem($resourceLink->getPlatform(), $label, $pointsPossible); 441 | $lineItem->resourceId = $resourceId; 442 | $lineItem->tag = $tag; 443 | $resourceLink->createLineItem($lineItem); 444 | } 445 | } 446 | } 447 | 448 | ### 449 | ### Create/update the outcomes in the line item associated with this item 450 | ### 451 | 452 | function updateLineItemOutcomes($resourceLink, $item) 453 | { 454 | global $db; 455 | 456 | if ($resourceLink->hasLineItemService()) { 457 | $id = strval($item->item_pk); 458 | $lineItems = $resourceLink->getLineItems($id); 459 | if (!empty($lineItems)) { 460 | $lineItem = $lineItems[0]; 461 | $users = $resourceLink->getUserResultSourcedIDs(); 462 | foreach ($users as $user) { 463 | $userRated = getUserRated($db, $resourceLink->getRecordId(), $user->getRecordId()); 464 | if (array_key_exists($id, $userRated)) { 465 | $outcome = new LTI\Outcome($userRated[$id], $item->max_rating); 466 | $lineItem->submitOutcome($outcome, $user); 467 | } 468 | } 469 | } 470 | } 471 | } 472 | 473 | ### 474 | ### Update the gradebook with proportion of visible items which have been rated by each user 475 | ### 476 | 477 | function updateGradebook($db, $userResourcePk = null, $userUserPk = null, $item = null, $rating = null) 478 | { 479 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 480 | $resourceLink = LTI\ResourceLink::fromRecordId($_SESSION['resource_pk'], $dataConnector); 481 | 482 | $num = getVisibleItemsCount($db, $_SESSION['resource_pk']); 483 | $ratings = getVisibleRatingsCounts($db, $_SESSION['resource_pk']); 484 | $users = $resourceLink->getUserResultSourcedIDs(); 485 | foreach ($users as $user) { 486 | $resourcePk = $user->getResourceLink()->getRecordId(); 487 | $userPk = $user->getRecordId(); 488 | $update = is_null($userResourcePk) || is_null($userUserPk) || (($userResourcePk === $resourcePk) && ($userUserPk === $userPk)); 489 | if ($update) { 490 | if ($num > 0) { 491 | $count = 0; 492 | if (isset($ratings[$resourcePk]) && isset($ratings[$resourcePk][$userPk])) { 493 | $count = $ratings[$resourcePk][$userPk]; 494 | } 495 | $ltiOutcome = new LTI\Outcome($count, $num); 496 | if ($count === 1) { 497 | $itemDesc = 'item'; 498 | } else { 499 | $itemDesc = 'items'; 500 | } 501 | $ltiOutcome->comment = "{$count} {$itemDesc} rated out of {$num}."; 502 | $resourceLink->doOutcomesService(ServiceAction::Write, $ltiOutcome, $user); 503 | } else { 504 | $ltiOutcome = new LTI\Outcome(); 505 | $resourceLink->doOutcomesService(ServiceAction::Delete, $ltiOutcome, $user); 506 | } 507 | } 508 | } 509 | if (!empty($userResourcePk) && !empty($userUserPk) && !empty($item) && !empty($rating)) { 510 | if ($userResourcePk !== $_SESSION['resource_pk']) { 511 | $resourceLink = LTI\ResourceLink::fromRecordId($userResourcePk, $dataConnector); 512 | } 513 | if ($resourceLink->hasLineItemService()) { 514 | $lineItems = $resourceLink->getLineItems(strval($item->item_pk)); 515 | if (!empty($lineItems)) { 516 | $user = LTI\UserResult::fromRecordId($userUserPk, $dataConnector); 517 | $outcome = new LTI\Outcome($rating, $item->max_rating); 518 | $lineItems[0]->submitOutcome($outcome, $user); 519 | } 520 | } 521 | } 522 | } 523 | 524 | ### 525 | ### Return a count of visible items for a specified resource link 526 | ### 527 | 528 | function getVisibleItemsCount($db, $resourcePk) 529 | { 530 | $prefix = DB_TABLENAME_PREFIX; 531 | $sql = <<< EOD 532 | SELECT COUNT(i.item_pk) count 533 | FROM {$prefix}item i 534 | WHERE (i.resource_link_pk = :resource_pk) AND (i.visible = 1) 535 | EOD; 536 | 537 | $query = $db->prepare($sql); 538 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_STR); 539 | $query->execute(); 540 | 541 | $row = $query->fetch(PDO::FETCH_NUM); 542 | if ($row === false) { 543 | $num = 0; 544 | } else { 545 | $num = intval($row[0]); 546 | } 547 | 548 | return $num; 549 | } 550 | 551 | ### 552 | ### Return a count of visible ratings made for items for a specified resource link by each user 553 | ### 554 | 555 | function getVisibleRatingsCounts($db, $resourcePk) 556 | { 557 | $prefix = DB_TABLENAME_PREFIX; 558 | $userTableName = DataConnector\DataConnector::USER_RESULT_TABLE_NAME; 559 | $sql = <<< EOD 560 | SELECT u.resource_link_pk, r.user_pk, COUNT(r.item_pk) count 561 | FROM {$prefix}item i INNER JOIN {$prefix}rating r ON i.item_pk = r.item_pk 562 | INNER JOIN {$prefix}{$userTableName} u ON r.user_pk = u.user_result_pk 563 | WHERE (i.resource_link_pk = :resource_pk) AND (i.visible = 1) 564 | GROUP BY u.resource_link_pk, r.user_pk 565 | EOD; 566 | $query = $db->prepare($sql); 567 | $query->bindValue('resource_pk', $resourcePk, PDO::PARAM_STR); 568 | $query->execute(); 569 | 570 | $rows = $query->fetchAll(PDO::FETCH_OBJ); 571 | $ratings = array(); 572 | if ($rows !== false) { 573 | foreach ($rows as $row) { 574 | $ratings[$row->resource_link_pk][$row->user_pk] = intval($row->count); 575 | } 576 | } 577 | 578 | return $ratings; 579 | } 580 | 581 | ### 582 | ### Return an array containing all the ratings for a specific user 583 | ### 584 | 585 | function getUserSummary($db, $userConsumerPk, $userPk) 586 | { 587 | $prefix = DB_TABLENAME_PREFIX; 588 | $sql = <<< EOD 589 | SELECT c.context_pk, i.resource_link_pk, i.max_rating, r.rating 590 | FROM {$prefix}lti_context c INNER JOIN {$prefix}item i ON c.consumer_key = i.consumer_key AND c.context_pk = i.resource_link_pk 591 | INNER JOIN {$prefix}rating r ON i.item_pk = r.item_pk 592 | WHERE r.consumer_pk = :consumer_pk AND r.user_pk = :user_pk 593 | EOD; 594 | 595 | $query = $db->prepare($sql); 596 | $query->bindValue('consumer_pk', $userConsumerPk, PDO::PARAM_INT); 597 | $query->bindValue('user_pk', $userPk, PDO::PARAM_STR); 598 | $query->execute(); 599 | 600 | $rows = $query->fetchAll(PDO::FETCH_OBJ); 601 | if ($rows === false) { 602 | $rows = array(); 603 | } 604 | 605 | return $rows; 606 | } 607 | 608 | ### 609 | ### Return an array containing all of a user's ratings for a specific context 610 | ### 611 | 612 | function getUserRatings($db, $contextPk, $userPk) 613 | { 614 | $prefix = DB_TABLENAME_PREFIX; 615 | $resourceLinkTableName = DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME; 616 | $sql = <<< EOD 617 | SELECT rl.resource_link_pk, i.max_rating, r.rating 618 | FROM {$prefix}{$resourceLinkTableName} rl INNER JOIN {$prefix}item i ON rl.resource_link_pk = i.resource_link_pk 619 | INNER JOIN {$prefix}rating r ON i.item_pk = r.item_pk 620 | WHERE rl.context_pk = :context_pk AND r.user_pk = :user_pk 621 | EOD; 622 | 623 | $query = $db->prepare($sql); 624 | $query->bindValue('context_pk', $contextPk, PDO::PARAM_INT); 625 | $query->bindValue('user_pk', $userPk, PDO::PARAM_INT); 626 | $query->execute(); 627 | 628 | $rows = $query->fetchAll(PDO::FETCH_OBJ); 629 | if ($rows === false) { 630 | $rows = array(); 631 | } 632 | 633 | return $rows; 634 | } 635 | 636 | ### 637 | ### Return an array containing all ratings for a specific context 638 | ### 639 | 640 | function getContextRatings($db, $contextPk) 641 | { 642 | $prefix = DB_TABLENAME_PREFIX; 643 | $resourceLinkTableName = DataConnector\DataConnector::RESOURCE_LINK_TABLE_NAME; 644 | $sql = <<< EOD 645 | SELECT rl.resource_link_pk title, i.max_rating, r.rating 646 | FROM {$prefix}{$resourceLinkTableName} rl INNER JOIN {$prefix}item i ON rl.resource_link_pk = i.resource_link_pk 647 | INNER JOIN {$prefix}rating r ON i.item_pk = r.item_pk 648 | WHERE rl.context_pk = :context_pk 649 | EOD; 650 | 651 | $query = $db->prepare($sql); 652 | $query->bindValue('context_pk', $contextPk, PDO::PARAM_INT); 653 | $query->execute(); 654 | 655 | $rows = $query->fetchAll(PDO::FETCH_OBJ); 656 | if ($rows === false) { 657 | $rows = array(); 658 | } 659 | 660 | return $rows; 661 | } 662 | 663 | ### 664 | ### Get the web path to the application 665 | ### 666 | 667 | function getAppPath($currentLevel = 0) 668 | { 669 | $path = getAppUrl($currentLevel); 670 | $pos = strpos($path, '/', 8); 671 | if ($pos !== false) { 672 | $path = substr($path, $pos); 673 | } 674 | 675 | return $path; 676 | } 677 | 678 | ### 679 | ### Get the URL to the application 680 | ### 681 | 682 | function getAppUrl($currentLevel = 0) 683 | { 684 | $request = OAuth\OAuthRequest::from_request(); 685 | $url = $request->get_normalized_http_url(); 686 | for ($i = 1; $i <= $currentLevel; $i++) { 687 | $pos = strrpos($url, '/'); 688 | if ($pos === false) { 689 | break; 690 | } else { 691 | $url = substr($url, 0, $pos); 692 | } 693 | } 694 | $pos = strrpos($url, '/'); 695 | if ($pos !== false) { 696 | $url = substr($url, 0, $pos + 1); 697 | } 698 | 699 | return $url; 700 | } 701 | 702 | ### 703 | ### Return a string representation of a float value 704 | ### 705 | 706 | function floatToStr($num) 707 | { 708 | $str = sprintf('%f', $num); 709 | $str = preg_replace('/0*$/', '', $str); 710 | if (substr($str, -1) == '.') { 711 | $str = substr($str, 0, -1); 712 | } 713 | 714 | return $str; 715 | } 716 | 717 | ### 718 | ### Return the value of a POST parameter 719 | ### 720 | 721 | function postValue($name, $defaultValue = null) 722 | { 723 | $value = $defaultValue; 724 | if (isset($_POST[$name])) { 725 | $value = $_POST[$name]; 726 | } 727 | 728 | return $value; 729 | } 730 | 731 | function pageFooter() 732 | { 733 | $here = function($val) { 734 | return $val; 735 | }; 736 | 737 | return <<< EOD 738 | 741 | 742 | EOD; 743 | } 744 | 745 | function ratingHtmlEntities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, $encoding = null, $double_encode = true) 746 | { 747 | if (is_int($string) || is_float($string)) { 748 | return strval($string); 749 | } else if (!is_string($string)) { 750 | return ''; 751 | } else { 752 | return htmlentities($string, $flags, $encoding, $double_encode); 753 | } 754 | } 755 | 756 | /** 757 | * Returns a string representation of a version 4 GUID, which uses random 758 | * numbers.There are 6 reserved bits, and the GUIDs have this format: 759 | * xxxxxxxx-xxxx-4xxx-[8|9|a|b]xxx-xxxxxxxxxxxx 760 | * where 'x' is a hexadecimal digit, 0-9a-f. 761 | * 762 | * See http://tools.ietf.org/html/rfc4122 for more information. 763 | * 764 | * Note: This function is available on all platforms, while the 765 | * com_create_guid() is only available for Windows. 766 | * 767 | * Source: https://github.com/Azure/azure-sdk-for-php/issues/591 768 | * 769 | * @return string A new GUID. 770 | */ 771 | function getGuid() 772 | { 773 | return sprintf('%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), // 32 bits for "time_low" 774 | mt_rand(0, 65535), // 16 bits for "time_mid" 775 | mt_rand(0, 4096) + 16384, // 16 bits for "time_hi_and_version", with 776 | // the most significant 4 bits being 0100 777 | // to indicate randomly generated version 778 | mt_rand(0, 64) + 128, // 8 bits for "clock_seq_hi", with 779 | // the most significant 2 bits being 10, 780 | // required by version 4 GUIDs. 781 | mt_rand(0, 256), // 8 bits for "clock_seq_low" 782 | mt_rand(0, 65535), // 16 bits for "node 0" and "node 1" 783 | mt_rand(0, 65535), // 16 bits for "node 2" and "node 3" 784 | mt_rand(0, 65535) // 16 bits for "node 4" and "node 5" 785 | ); 786 | } 787 | 788 | ### 789 | ### Class representing an item 790 | ### 791 | 792 | class Item 793 | { 794 | 795 | public $item_pk = null; 796 | public $item_title = ''; 797 | public $item_text = ''; 798 | public $item_url = ''; 799 | public $max_rating = 3; 800 | public $step = 1; 801 | public $visible = false; 802 | public $sequence = 0; 803 | public $created = null; 804 | public $updated = null; 805 | public $num_ratings = 0; 806 | public $tot_ratings = 0; 807 | 808 | // ensure non-string properties have the appropriate data type 809 | function __set($name, $value) 810 | { 811 | if ($name == 'mr') { 812 | $this->max_rating = intval($value); 813 | } else if ($name == 'st') { 814 | $this->step = intval($value); 815 | } else if ($name == 'vis') { 816 | $this->visible = $value == '1'; 817 | } else if ($name == 'seq') { 818 | $this->sequence = intval($value); 819 | } else if ($name == 'cr') { 820 | $this->created = DateTime::createFromFormat('Y-m-d H:i:s', $value); 821 | } else if ($name == 'upd') { 822 | $this->updated = DateTime::createFromFormat('Y-m-d H:i:s', $value); 823 | } else if ($name == 'num') { 824 | $this->num_ratings = intval($value); 825 | } else if ($name == 'total') { 826 | $this->tot_ratings = floatval($value); 827 | } 828 | } 829 | 830 | } 831 | 832 | ?> -------------------------------------------------------------------------------- /src/rating.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright SPV Software Products 7 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 8 | */ 9 | require_once('lib.php'); 10 | 11 | // Initialise session and database 12 | $db = null; 13 | $ok = init($db, true); 14 | if ($ok) { 15 | // Ensure request is complete and for a student 16 | $ok = isset($_POST['id']) && isset($_POST['value']) && $_SESSION['isStudent']; 17 | } 18 | if ($ok) { 19 | // Save rating 20 | $ok = false; 21 | $item = getItem($db, $_SESSION['resource_pk'], intval($_POST['id'])); 22 | if (($item !== false) && saveRating($db, $_SESSION['user_pk'], $_POST['id'], $_POST['value'])) { 23 | updateGradebook($db, $_SESSION['user_resource_pk'], $_SESSION['user_pk'], $item, $_POST['value']); 24 | $ok = true; 25 | } 26 | } 27 | 28 | // Generate response 29 | if ($ok) { 30 | $response = array('response' => 'Success'); 31 | } else { 32 | $response = array('response' => 'Fail'); 33 | } 34 | 35 | // Return response 36 | header('Content-type: application/json'); 37 | echo json_encode($response); 38 | ?> 39 | -------------------------------------------------------------------------------- /src/rating_tp.php: -------------------------------------------------------------------------------- 1 | 12 | * @copyright SPV Software Products 13 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 14 | */ 15 | require_once('lib.php'); 16 | 17 | class RatingTool extends LTI\Tool 18 | { 19 | 20 | function __construct($dataConnector) 21 | { 22 | parent::__construct($dataConnector); 23 | 24 | $this->allowSharing = true; 25 | 26 | $this->baseUrl = getAppUrl(); 27 | 28 | $this->vendor = new Profile\Item('celtic', 'ceLTIc Project', 'ceLTIc Project', 'https://www.celtic-project.org/'); 29 | $this->product = new Profile\Item('d751f24f-140e-470f-944c-2d92b114db40', 'Rating', 30 | 'Sample LTI tool to create lists of items to be rated.', 'http://www.spvsoftwareproducts.com/php/rating/', APP_VERSION); 31 | 32 | $requiredMessages = array(new Profile\Message('basic-lti-launch-request', 'connect.php', array('User.id', 'Membership.role'))); 33 | $optionalMessages = array(new Profile\Message('ContentItemSelectionRequest', 'connect.php', 34 | array('User.id', 'Membership.role')), 35 | new Profile\Message('DashboardRequest', 'connect.php', array('User.id')) 36 | ); 37 | 38 | $this->resourceHandlers[] = new Profile\ResourceHandler( 39 | new Profile\Item('rating', 'Rating app', 'An example tool which generates lists of items for rating.'), 40 | 'images/icon50.png', $requiredMessages, $optionalMessages); 41 | 42 | $this->requiredServices[] = new Profile\ServiceDefinition(array('application/vnd.ims.lti.v2.toolproxy+json'), array('POST')); 43 | 44 | if (isset($_SESSION['lti_version']) && ($_SESSION['lti_version'] === LtiVersion::V1P3)) { 45 | $this->signatureMethod = SIGNATURE_METHOD; 46 | } 47 | $this->jku = getAppUrl() . 'jwks.php'; 48 | $this->kid = KID; 49 | $this->rsaKey = PRIVATE_KEY; 50 | $this->requiredScopes = array( 51 | LTI\Service\LineItem::$SCOPE, 52 | LTI\Service\Score::$SCOPE, 53 | LTI\Service\Membership::$SCOPE, 54 | LTI\Service\Groups::$SCOPE 55 | ); 56 | } 57 | 58 | protected function onLaunch(): void 59 | { 60 | // Check the user has an appropriate role 61 | if ($this->userResult->isLearner() || $this->userResult->isStaff()) { 62 | // Initialise the user session 63 | $_SESSION['consumer_pk'] = $this->platform->getRecordId(); 64 | $_SESSION['resource_pk'] = $this->resourceLink->getRecordId(); 65 | $_SESSION['user_consumer_pk'] = $this->userResult->getResourceLink()->getPlatform()->getRecordId(); 66 | $_SESSION['user_resource_pk'] = $this->userResult->getResourceLink()->getRecordId(); 67 | $_SESSION['user_pk'] = $this->userResult->getRecordId(); 68 | $_SESSION['isStudent'] = $this->userResult->isLearner(); 69 | $_SESSION['isContentItem'] = false; 70 | $_SESSION['lti_version'] = $this->platform->ltiVersion; 71 | 72 | // Redirect the user to display the list of items for the resource link 73 | $this->redirectUrl = getAppUrl(); 74 | } else { 75 | $this->reason = 'Invalid role.'; 76 | $this->ok = false; 77 | } 78 | } 79 | 80 | protected function onContentItem(): void 81 | { 82 | // Check that the Platform is allowing the return of an LTI link 83 | $this->ok = in_array(LTI\ContentItem::LTI_LINK_MEDIA_TYPE, $this->mediaTypes) || in_array('*/*', $this->mediaTypes); 84 | if (!$this->ok) { 85 | $this->reason = 'Return of an LTI link not offered'; 86 | } else { 87 | $this->ok = !in_array('none', $this->documentTargets) || (count($this->documentTargets) > 1); 88 | if (!$this->ok) { 89 | $this->reason = 'No visible document target offered'; 90 | } 91 | } 92 | if ($this->ok) { 93 | // Initialise the user session 94 | $_SESSION['consumer_pk'] = $this->platform->getRecordId(); 95 | $_SESSION['resource_id'] = getGuid(); 96 | $_SESSION['resource_pk'] = null; 97 | $_SESSION['user_consumer_pk'] = $_SESSION['consumer_pk']; 98 | $_SESSION['user_pk'] = null; 99 | $_SESSION['isStudent'] = false; 100 | $_SESSION['isContentItem'] = true; 101 | $_SESSION['lti_version'] = $this->platform->ltiVersion; 102 | $_SESSION['return_url'] = $this->returnUrl; 103 | $_SESSION['title'] = postValue('title', 'Rating item'); 104 | $_SESSION['text'] = postValue('text'); 105 | $_SESSION['data'] = postValue('data'); 106 | $_SESSION['document_targets'] = $this->documentTargets; 107 | // Redirect the user to display the list of items for the resource link 108 | $this->redirectUrl = getAppUrl(); 109 | } 110 | } 111 | 112 | protected function onDashboard(): void 113 | { 114 | global $db; 115 | 116 | $title = APP_NAME; 117 | $appUrl = 'http://www.spvsoftwareproducts.com/php/rating/'; 118 | $iconUrl = getAppUrl() . 'images/icon50.png'; 119 | if (empty($this->context)) { 120 | $ratings = getUserSummary($db, $this->userResult->getResourceLink()->getPlatform()->getRecordId(), 121 | $this->userResult->getRecordId()); 122 | $numRatings = count($ratings); 123 | $courses = array(); 124 | $lists = array(); 125 | $tot_rating = 0; 126 | foreach ($ratings as $rating) { 127 | $courses[$rating->lti_context_id] = true; 128 | $lists[$rating->resource_id] = true; 129 | $tot_rating += ($rating->rating / $rating->max_rating); 130 | } 131 | $numCourses = count($courses); 132 | $numLists = count($lists); 133 | if ($numRatings > 0) { 134 | $av_rating = floatToStr($tot_rating / $numRatings * 5); 135 | } 136 | $html = <<< EOD 137 |

138 | Here is a summary of your rating of items: 139 |

140 |
    141 |
  • Number of courses: {$numCourses}
  • 142 |
  • Number of rating lists: {$numLists}
  • 143 |
  • Number of ratings made: {$numRatings}
  • 144 | 145 | EOD; 146 | if ($numRatings > 0) { 147 | $html .= <<< EOD 148 |
  • Average rating: {$av_rating} out of 5
  • 149 | 150 | EOD; 151 | } 152 | $html .= <<< EOD 153 |
154 | 155 | EOD; 156 | $this->output = $html; 157 | } else { 158 | if ($this->userResult->isLearner()) { 159 | $ratings = getUserRatings($db, $this->context->getRecordId(), $this->userResult->getRecordId()); 160 | } else { 161 | $ratings = getContextRatings($db, $this->context->getRecordId()); 162 | } 163 | $resources = array(); 164 | $totals = array(); 165 | foreach ($ratings as $rating) { 166 | $tot = ($rating->rating / $rating->max_rating); 167 | if (array_key_exists($rating->title, $resources)) { 168 | $resources[$rating->title] += 1; 169 | $totals[$rating->title] += $tot; 170 | } else { 171 | $resources[$rating->title] = 1; 172 | $totals[$rating->title] = $tot; 173 | } 174 | } 175 | ksort($resources); 176 | $items = ''; 177 | $n = 0; 178 | foreach ($resources as $title => $value) { 179 | $n++; 180 | $av = floatToStr($totals[$title] / $value * 5); 181 | $plural = ''; 182 | if ($value <> 1) { 183 | $plural = 's'; 184 | } 185 | $items .= <<< EOD 186 | 187 | Link {$n} 188 | {$value} item{$plural} rated (average {$av} out of 5) 189 | 190 | EOD; 191 | } 192 | $rss = <<< EOD 193 | 194 | 195 | Dashboard 196 | {$appUrl} 197 | 198 | 199 | {$iconUrl} 200 | Dashboard 201 | {$appUrl} 202 | {$title} Dashboard 203 | {$items} 204 | 205 | 206 | EOD; 207 | header('Content-type: text/xml'); 208 | $this->output = $rss; 209 | } 210 | } 211 | 212 | protected function onRegister(): void 213 | { 214 | // Initialise the user session 215 | $_SESSION['consumer_pk'] = $this->platform->getRecordId(); 216 | $_SESSION['tc_profile_url'] = $_POST['tc_profile_url']; 217 | $_SESSION['tc_profile'] = $this->platform->profile; 218 | $_SESSION['return_url'] = $_POST['launch_presentation_return_url']; 219 | 220 | // Redirect the user to process the registration 221 | $this->redirectUrl = getAppUrl() . 'register.php'; 222 | } 223 | 224 | protected function onRegistration(): void 225 | { 226 | if (!defined('AUTO_ENABLE') || !AUTO_ENABLE) { 227 | $successMessage = 'Note that the tool must be enabled by the tool provider before it can be used.'; 228 | } else if (!defined('ENABLE_FOR_DAYS') || (ENABLE_FOR_DAYS <= 0)) { 229 | $successMessage = 'The tool has been automatically enabled by the tool provider for immediate use.'; 230 | } else { 231 | $successMessage = 'The tool has been enabled for you to use for the next ' . ENABLE_FOR_DAYS . ' day'; 232 | if (ENABLE_FOR_DAYS > 1) { 233 | $successMessage .= 's'; 234 | } 235 | } 236 | $appName = APP_NAME; 237 | $html = <<< EOD 238 | 239 | 240 | 241 | 242 | 243 | LTI Tool registration 244 | 245 | 246 | 284 | 285 | 286 |

{$appName} Tool Registration

287 | 288 |

289 | This page allows you to perform a dynamic registration with an LTI 1.3 platform. 290 |

291 | 292 |

293 | 294 |

295 |

296 | 297 |

298 | 299 |

300 | The tool registration was successful. {$successMessage} 301 |

302 |

303 | The tool registration failed 304 |

305 | 306 |

307 | 308 |

309 | 310 | 311 | 312 | EOD; 313 | $this->output = $html; 314 | } 315 | 316 | protected function onError(): void 317 | { 318 | $msg = $this->message; 319 | if ($this->debugMode && !empty($this->reason)) { 320 | $msg = $this->reason; 321 | } 322 | $title = APP_NAME; 323 | 324 | $this->errorOutput = <<< EOD 325 | 326 | 327 | 328 | 329 | 330 | {$title} 331 | 332 | 333 | 334 | 335 | 336 | 337 |

Error

338 |

{$msg}

339 | 340 | 341 | EOD; 342 | } 343 | 344 | public function doRegistration(): void 345 | { 346 | $platformConfig = $this->getPlatformConfiguration(); 347 | if ($this->ok) { 348 | $toolConfig = $this->getConfiguration($platformConfig); 349 | $registrationConfig = $this->sendRegistration($platformConfig, $toolConfig); 350 | if ($this->ok) { 351 | $this->getPlatformToRegister($platformConfig, $registrationConfig, false); 352 | if (defined('AUTO_ENABLE') && AUTO_ENABLE) { 353 | $this->platform->enabled = true; 354 | } 355 | if (defined('ENABLE_FOR_DAYS') && (ENABLE_FOR_DAYS > 0)) { 356 | $now = time(); 357 | $this->platform->enableFrom = $now; 358 | $this->platform->enableUntil = $now + (ENABLE_FOR_DAYS * 24 * 60 * 60); 359 | } 360 | $this->ok = $this->platform->save(); 361 | if (!$this->ok) { 362 | $checkPlatform = Platform::fromPlatformId($this->platform->platformId, $this->platform->clientId, 363 | $this->platform->deploymentId, $this->dataConnector); 364 | if (!empty($checkPlatform->created)) { 365 | $this->reason = 'The platform is already registered.'; 366 | } else { 367 | $this->reason = 'Sorry, an error occurred when saving the platform details.'; 368 | } 369 | } 370 | } 371 | } 372 | } 373 | 374 | } 375 | 376 | ?> 377 | -------------------------------------------------------------------------------- /src/register.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright SPV Software Products 11 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 12 | */ 13 | require_once('rating_tp.php'); 14 | 15 | // Initialise session and database 16 | $page = ''; 17 | $db = null; 18 | if (init($db)) { 19 | 20 | // Register 21 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { 22 | 23 | $errorMsg = ''; 24 | $url = $_SESSION['return_url']; 25 | if (strpos($url, '?') === false) { 26 | $sep = '?'; 27 | } else { 28 | $sep = '&'; 29 | } 30 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 31 | $tool = new RatingTool($dataConnector); 32 | $tool->platform = LTI\Platform::fromRecordId($_SESSION['consumer_pk'], $dataConnector); 33 | $do = $_POST['do']; 34 | if ($do == 'Register') { 35 | $ok = $tool->doToolProxyService($_SESSION['tc_profile_url']); 36 | if ($ok) { 37 | $guid = $tool->platform->getKey(); 38 | header("Location: {$url}{$sep}lti_msg=The%20tool%20has%20been%20registered&status=success&tool_proxy_guid={$guid}"); 39 | exit; 40 | } else { 41 | $errorMsg = 'Error setting tool proxy'; 42 | } 43 | } else if ($do == 'Cancel') { 44 | $tool->platform->delete(); 45 | header("Location: {$url}{$sep}lti_msg=The%20tool%20registration%20has%20been%20cancelled&status=failure"); 46 | exit; 47 | } 48 | } 49 | 50 | $page .= <<< EOD 51 |
52 | 53 | EOD; 54 | if (!empty($errorMsg)) { 55 | $page .= <<< EOD 56 |

57 | {$errorMsg} 58 |

59 | EOD; 60 | } 61 | $page .= <<< EOD 62 |
63 |

64 | Your system meets the minimum requirements for this tool. Click the button below to complete the registration process. 65 |

66 |

67 | 68 |     69 |

70 |
71 |
72 | 73 | EOD; 74 | } 75 | 76 | $title = APP_NAME; 77 | $page = <<< EOD 78 | 79 | 80 | 81 | 82 | 83 | {$title} 84 | 85 | 86 | 87 | 88 |

Rating Application Registration

89 | {$page} 90 | 91 | 92 | EOD; 93 | 94 | // Display page 95 | echo $page; 96 | ?> 97 | -------------------------------------------------------------------------------- /src/registration.php: -------------------------------------------------------------------------------- 1 | 9 | * @copyright SPV Software Products 10 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 11 | */ 12 | require_once('rating_tp.php'); 13 | 14 | // Initialise session and database 15 | $db = null; 16 | if (init($db)) { 17 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 18 | $tool = new RatingTool($dataConnector); 19 | $tool->doRegistration(); 20 | $ok = $tool->ok; 21 | $message = $tool->reason; 22 | } else { 23 | $ok = false; 24 | $message = 'Unable to connect to database.'; 25 | } 26 | 27 | $response = array(); 28 | $response['ok'] = $ok; 29 | $response['message'] = $message; 30 | 31 | header('Content-type: application/json'); 32 | echo json_encode($response); 33 | ?> 34 | -------------------------------------------------------------------------------- /src/share.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright SPV Software Products 14 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 15 | */ 16 | require_once('lib.php'); 17 | 18 | // Initialise session and database 19 | $db = null; 20 | $ok = init($db, true); 21 | 22 | $response = ''; 23 | if ($ok) { 24 | // Initialise parameters 25 | $action = ''; 26 | // Check for item id and action parameters 27 | $action = ''; 28 | if (isset($_REQUEST['do'])) { 29 | $action = strtolower($_REQUEST['do']); 30 | } 31 | $life = 0; 32 | if (isset($_REQUEST['life'])) { 33 | $life = intval($_REQUEST['life']); 34 | } 35 | $rlid = 0; 36 | if (isset($_REQUEST['rlid'])) { 37 | $rlid = intval($_REQUEST['rlid']); 38 | } 39 | // Process share action 40 | $dataConnector = DataConnector\DataConnector::getDataConnector($db, DB_TABLENAME_PREFIX); 41 | if (($action == 'generate') && !empty($life)) { 42 | $resourceLink = ResourceLink::fromRecordId($_SESSION['resource_pk'], $dataConnector); 43 | $autoApprove = false; 44 | if (isset($_REQUEST['auto_approve'])) { 45 | $autoApprove = $_REQUEST['auto_approve'] === 'yes'; 46 | } 47 | $length = intval($resourceLink->getSetting('custom_share_key_length')); 48 | if (empty($length)) { 49 | $length = 6; 50 | } 51 | $shareKey = new ResourceLinkShareKey($resourceLink); 52 | $shareKey->length = $length; 53 | $shareKey->life = $life; 54 | $shareKey->autoApprove = $autoApprove; 55 | $ok = $shareKey->save(); 56 | $response = $shareKey->getId(); 57 | } else if ((($action == 'approve') || ($action == 'suspend')) && !empty($rlid)) { 58 | $resourceLink = ResourceLink::fromRecordId($rlid, $dataConnector); 59 | $resourceLink->shareApproved = ($action === 'approve'); 60 | $ok = $resourceLink->save(); 61 | } else if (($action == 'cancel') && !empty($rlid)) { 62 | $resourceLink = ResourceLink::fromRecordId($rlid, $dataConnector); 63 | $resourceLink->primaryResourceLinkId = null; 64 | $resourceLink->shareApproved = null; 65 | $resourceLink->save(); 66 | header('Location: index.php'); 67 | exit; 68 | } 69 | } 70 | 71 | if ($ok) { 72 | echo $response; 73 | } else { 74 | header("Status: 404 Not Found", true, 404); 75 | } 76 | ?> 77 | -------------------------------------------------------------------------------- /src/vendor/autoload.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright SPV Software Products 7 | * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 8 | */ 9 | spl_autoload_register(function ($class) { 10 | 11 | // base directory for the class files 12 | $base_dir = __DIR__ . DIRECTORY_SEPARATOR; 13 | 14 | // Replace the namespace prefix with the base directory, replace namespace 15 | // separators with directory separators in the relative class name, append 16 | // with .php 17 | $file = $base_dir . preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $class) . '.php'; 18 | 19 | // Update location if class requested is from the ceLTIc\LTI class library 20 | $file = str_replace(DIRECTORY_SEPARATOR . 'ceLTIc' . DIRECTORY_SEPARATOR . 'LTI' . DIRECTORY_SEPARATOR, 21 | DIRECTORY_SEPARATOR . 'celtic' . DIRECTORY_SEPARATOR . 'lti' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $file); 22 | 23 | // Update location if class requested is from the Firebase\php-jwt class library 24 | $file = str_replace(DIRECTORY_SEPARATOR . 'Firebase' . DIRECTORY_SEPARATOR . 'JWT' . DIRECTORY_SEPARATOR, 25 | DIRECTORY_SEPARATOR . 'firebase' . DIRECTORY_SEPARATOR . 'php-jwt' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, 26 | $file); 27 | 28 | // if the file exists, require it 29 | if (file_exists($file)) { 30 | require($file); 31 | } 32 | }); 33 | ?> 34 | --------------------------------------------------------------------------------